psycopg2.OperationalError: SSL SYSCALL error: EOF detected

AnonymousTRIAL

a year ago

I am running a Discord bot SSApp on Railway, and when I execute SQL to a Postgres DB, I get this error.
After that, the following error occurs and access to the DB becomes impossible.

psycopg2.InterfaceError: connection already closed

Project ID : 8153aade-2cb8-4e3e-a2c6-36ad01e8f5fd

Solved

0 Replies

a year ago

make sure you aren't keeping idle connections open


AnonymousTRIAL

a year ago

Regarding psycopg2, I changed the description in requirements.txt from psycopg2-binary to psycopg2 and this error no longer occurs.
Instead, the following error occurs periodically. What is the cause of this?

discord.errors.ConnectionClosed: Shard ID None WebSocket closed with 1000


AnonymousTRIAL

a year ago

I think it is a normal implementation, though I use psycopg2.connect to connect when the bot starts and close when the bot exits.


AnonymousTRIAL

a year ago

No, I still get the first error. Can someone tell me what's causing it?


a year ago

you are keeping closed connections around


AnonymousTRIAL

a year ago

I'm asking because this is the error that triggered the disconnection.


AnonymousTRIAL

a year ago

After changing the Postgres operation from psycopg2 to asyncpg, the first error does not seem to occur now. However, the following errors occur periodically

Traceback (most recent call last):
File "/opt/venv/lib/python3.9/site-packages/discord/client.py", line 659, in connect
await self.ws.poll_event()
File "/opt/venv/lib/python3.9/site-packages/discord/gateway.py", line 646, in poll_event
raise ConnectionClosed(self.socket, shard_id=self.shard_id, code=code) from None
discord.errors.ConnectionClosed: Shard ID None WebSocket closed with 1000

a year ago

make sure you aren't keeping idle connections open


AnonymousTRIAL

a year ago

I have tried connecting only when DB operations are required and disconnecting when done, but the error still occurs


AnonymousTRIAL

a year ago

hi @たけ , I had that issue under circumstances very similar to yours and this seems to have fixed it:

  • adding 'NullPool' to the engine: engine = createengine(DATABASEURL, echo=True, future=True, poolpreping=True, poolclass=NullPool)

  • using a sessionmaker to do all db-related operations inside context managers with session objects instantiated from sessionmaker

hope this helps


Status changed to Solved railway[bot] about 1 year ago


AnonymousTRIAL

a year ago

not sure if only one of those changes or both did the trick though


psycopg2.OperationalError: SSL SYSCALL error: EOF detected - Railway Help Station