R
Railway9mo ago
たけ

psycopg2.OperationalError: SSL SYSCALL error: EOF detected

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
Solution:
hi @たけ , I had that issue under circumstances very similar to yours and this seems to have fixed it: * adding 'NullPool' to the engine: engine = create_engine(DATABASE_URL, echo=True, future=True, pool_pre_ping=True, poolclass=NullPool) * using a sessionmaker to do all db-related operations inside context managers with session objects instantiated from sessionmaker hope this helps...
Jump to solution
9 Replies
Percy
Percy9mo ago
Project ID: 8153aade-2cb8-4e3e-a2c6-36ad01e8f5fd
Brody
Brody9mo ago
make sure you aren't keeping idle connections open
たけ
たけ9mo 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 I think it is a normal implementation, though I use psycopg2.connect to connect when the bot starts and close when the bot exits. No, I still get the first error. Can someone tell me what's causing it?
Brody
Brody9mo ago
you are keeping closed connections around
たけ
たけ9mo ago
I'm asking because this is the error that triggered the disconnection. 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
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
Brody
Brody9mo ago
make sure you aren't keeping idle connections open
たけ
たけ9mo ago
I have tried connecting only when DB operations are required and disconnecting when done, but the error still occurs
Solution
asakura
asakura8mo 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 = create_engine(DATABASE_URL, echo=True, future=True, pool_pre_ping=True, poolclass=NullPool) * using a sessionmaker to do all db-related operations inside context managers with session objects instantiated from sessionmaker hope this helps
asakura
asakura8mo ago
not sure if only one of those changes or both did the trick though
Want results from more Discord servers?
Add your server