Error during garbage collection after calling isready() on a closed connection
Brian Sutherland <[email protected]>
| Newsgroups | gmane.comp.python.db.psycopg.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi, Attached is an example script of a nasty little bug I found. It looks like calling .isready() on a server closed connection causes an error during the next garbage collection. That can cause all sorts of havoc on a python process. I found it in version 2.5.1 and verified that it's still there in 2.0.8. ~ # python test_isready_connection_closed.py Testing psycopg2 version 2.0.8 (dec dt ext pq3) Now restart the test postgresql server to drop all connections, press enter when done. Exception psycopg2.OperationalError: 'server closed the connection unexpectedly\n\tThis probably means the server terminated abnormally\n\tbefore or while processing the request.\n' in 'garbage collection' ignored Fatal Python error: unexpected exception during garbage collection -- Brian Sutherland _______________________________________________ Psycopg mailing list Psycopg-IAPFreCvJWPBWskQ1e/[email protected] http://lists.initd.org/mailman/listinfo/psycopg
test_isready_connection_closed.py
(text/plain, 656 B)
import gc
import sys
import os
import signal
import warnings
import psycopg2
print "Testing psycopg2 version %s" % psycopg2.__version__
dbname = os.environ.get('PSYCOPG2_TESTDB', 'psycopg2_test')
conn = psycopg2.connect("dbname=%s" % dbname)
curs = conn.cursor()
curs.isready()
print "Now restart the test postgresql server to drop all connections, press enter when done."
raw_input()
curs.isready() # No need to test return value
if curs.isready():
print "Warning: looks like the connection didn't get killed. This test is probably in-effective"
print "Test inconclusive"
sys.exit(1)
gc.collect() # used to error here
print "Test Passed"