NeonN
Neon2y ago
25 replies
efficient-indigo

psycopg.OperationalError: consuming input failed: SSL SYSCALL error: EOF detected

I'm running some tasks which are actually taking more time than five minutes and I've already established connection with NeonDB(Postgres) as it's serverless when i use cursor.query it's throwing me error psycopg.OperationalError: consuming input failed: SSL SYSCALL error: EOF detected, I'm using below code

import os
from psycopg_pool import ConnectionPool
from time import sleep

# Create a connection pool
dbPool = ConnectionPool(
    conninfo="postgresurl?sslmode=require",
    min_size=2,
    max_size=10,
)


def dbConnection():
    '''
    Function to create a connection and cursor
    '''
    con = dbPool.getconn()
    cursor = con.cursor()
    return con, cursor


# Establishing DB Connection
con, cursor = dbConnection()
print("Sleep has started")
sleep(630)
print("Sleep has ended")
query = f"""UPDATE kPost SET score=0 WHERE postId='01HS94YD7K0JPN72ZMMK7WADAH';"""
cursor.execute(query)
print("Query executed")
con.commit()
print("Query committed")
con.close()
print("Connection closed")


Output is as below:
Sleep has started
Sleep has ended
Traceback (most recent call last):
  File "/Users/dharmesh/Documents/.kBackend/kContainers/dbConnectionDisconnection/dbConnection.py", line 28, in <module>
    cursor.execute(query)
  File "/Users/dharmesh/Documents/.kBackend/kContainers/venv/lib/python3.11/site-packages/psycopg/cursor.py", line 732, in execute
    raise ex.with_traceback(None)
psycopg.OperationalError: consuming input failed: SSL SYSCALL error: EOF detected


It took almost 16m, Even though sleep is for just five and a half minute, As cursor.query() might be trying and trying for connection

What can i do to avoid this issue ?
Was this page helpful?