This project is archived and is in readonly mode.
connection.closed attribute is not set properly on localconnections
-
Zaar Hai
Formatting did not go well through web form. The reproduction is below.
$ python Python 2.7.5+ (default, Sep 19 2013, 13:48:49) [GCC 4.8.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import psycopg2 >>> conn = psycopg2.connect("dbname=tst host=/tmp") >>> conn.closed 0 >>> # Issuse CTRL-Z [1]+ Stopped python $ service postgresql restart * Restarting PostgreSQL 9.1 database server ...done. $ fg python >>> cur = conn.cursor() >>> cur.execute("SELECT 1") Traceback (most recent call last): File "<stdin>", line 1, in <module> psycopg2.OperationalError: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. >>> conn.closed # <------------ Should be greater then zero! 0 >>> psycopg2.__version__ '2.5.2 (dt dec pq3 ext)' >>> -
Daniele Varrazzo
- State changed from new to open
Yup, thank you for the report: i'd noticed something similar in #192 enhancement: connection.closed attribute to actually become a property that d.... Thank you for the test case, I'll try to fix it.
-
Zaar Hai
BTW, to emphasize, that if one connects through TCP and not local socket, then
closedattribute is populated properly. -
Daniele Varrazzo
Ugh, thank you for the clarification, I wouldn't have expected such a difference.
-
Zaar Hai
Yeah, I've spotted it while working on Momoko - dead connection detection stopped functioning when one connects through local socket.
-
Daniele Varrazzo
In debug mode, executing into a broken socket connection:
In [4]: cur.execute('select 1') [19233] psyco_curs_execute: starting execution of new query [19233] curs_execute: pg connection at 0x2095ff0 OK [19233] pq_begin_locked: pgconn = 0x2095ff0, autocommit = 0, status = 1 [19233] pq_execute_command_locked: pgconn = 0x2095ff0, query = BEGIN [19233] pq_execute_command_locked: PQexec returned NULL [19233] pq_complete_error: pgconn = 0x2095ff0, pgres = (nil), error = server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. [19233] psyco_curs_execute: res = -1, pgres = (nil)In a tcp connection instead:
[19233] psyco_curs_execute: starting execution of new query [19233] curs_execute: pg connection at 0x20e8120 OK [19233] pq_begin_locked: pgconn = 0x20e8120, autocommit = 0, status = 1 [19233] pq_execute_command_locked: pgconn = 0x20e8120, query = BEGIN [19233] pq_execute_command_locked: result was not COMMAND_OK (7) [19233] pq_complete_error: pgconn = 0x20e8120, pgres = 0x2158e30, error = (null) [19233] pq_raise: PQresultErrorMessage: err=FATAL: terminating connection due to administrator command SSL connection has been closed unexpectedlyso this should be the branch point: PQexec returning NULL vs. a "not ok" result.
-
Zaar Hai
Verified: works for me at https://github.com/dvarrazzo/psycopg.git#d1e1243ba851641feb2920148a...
Waiting for 2.5.3.
Thanks! -
Daniele Varrazzo
- Milestone set to psycopg2 2.5.3
Thank you for testing: I'll try to clear the issues with poll too and pack up the release within a few days.
-
Daniele Varrazzo
- State changed from open to resolved