mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-14 21:16:34 +03:00
ac14957fbb
There's a race condition that only seems to happen over Unix-domain sockets. Sometimes, the closed socket is reported by the kernel to libpq like this (captured with strace): sendto(3, "Q\0\0\0\34select pg_backend_pid()\0", 29, MSG_NOSIGNAL, NULL, 0) = 29 recvfrom(3, "E\0\0\0mSFATAL\0C57P01\0Mterminating "..., 16384, 0, NULL, NULL) = 110 recvfrom(3, 0x12d0330, 16384, 0, 0, 0) = -1 ECONNRESET (Connection reset by peer) That is, psycopg2/libpq sees no error when sending the first query after the connection is closed, but gets an error reading the result. In that case, everything worked fine. But sometimes, the error manifests like this: sendto(3, "Q\0\0\0\34select pg_backend_pid()\0", 29, MSG_NOSIGNAL, NULL, 0) = -1 EPIPE (Broken pipe) recvfrom(3, "E\0\0\0mSFATAL\0C57P01\0Mterminating "..., 16384, 0, NULL, NULL) = 110 recvfrom(3, "", 16274, 0, NULL, NULL) = 0 recvfrom(3, "", 16274, 0, NULL, NULL) = 0 i.e. libpq received an error when sending the query. This manifests as a slightly different exception from a slightly different place. More importantly, in this case connection.closed is left at 0 rather than being set to 2, and that is the bug I'm fixing here. Note that we see almost identical behaviour for sync and async connections, and the fixes are the same. So I added extremely similar test cases. Finally, there is still a bug here: for async connections, we sometimes raise DatabaseError (incorrect) and sometimes raise OperationalError (correct). Will fix that next. |
||
---|---|---|
.. | ||
__init__.py | ||
dbapi20_tpc.py | ||
dbapi20.py | ||
test_async.py | ||
test_bug_gc.py | ||
test_bugX000.py | ||
test_cancel.py | ||
test_connection.py | ||
test_copy.py | ||
test_cursor.py | ||
test_dates.py | ||
test_errcodes.py | ||
test_extras_dictcursor.py | ||
test_green.py | ||
test_lobject.py | ||
test_module.py | ||
test_notify.py | ||
test_psycopg2_dbapi20.py | ||
test_quote.py | ||
test_transaction.py | ||
test_types_basic.py | ||
test_types_extras.py | ||
test_with.py | ||
testconfig.py | ||
testutils.py |