0

I build multiple process for each cpu core. When I try to test it and send multiple requests from these processes, I get an exception:

psycopg2.OperationalError: SSL error: decryption failed or bad record mac

It works fine in single process mode, but when I build more than one process, this error shown.

Mahdi Perfect
  • 364
  • 3
  • 7

2 Answers2

1

It is likely because your processes are sharing the same connection pool and writing concurrently to the same postgres connection(s).

You do not provide much information on how you implement multi-processing, but if are forking processes, a common pitfall is that the engine is created before the fork, which initializes TCP connection(s) to the database which then gets copied over to the new processes and results in multiple processes interacting with the same physical sockets.

Remedies include:

  • Disabling the pool and using an on demand connection: poolclass=NullPool,
  • Re-creating the pool after fork: sqla_engine.dispose(), or
  • Delaying the create_engine until after the fork
TheArchitect
  • 2,161
  • 1
  • 12
  • 16
-1

You can disable SSL on postgres config file. Change this line:

ssl = true

to

ssl = false

Config file is usually on /etc/postgresql/*.*/main/postgresql.conf

Mahdi Perfect
  • 364
  • 3
  • 7