Commit Graph

1785 Commits

Author SHA1 Message Date
Greg Ward
ac14957fbb Always detect when a connection is closed behind psycopg2's back.
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.
2016-06-28 17:46:21 -04:00
Karl O. Pinc
2714c9c638 Improve sentence. 2016-03-10 12:07:38 +00:00
Jan Janßen
072b6ef98b Update psycopg1.py 2016-03-10 11:58:37 +00:00
Daniele Varrazzo
5aa7588f56 Merge branch 'py35' into maint_2_6 2016-03-08 05:15:47 +00:00
Daniele Varrazzo
0fa44ea943 Start advertising Py 3.5 support 2016-03-08 05:13:57 +00:00
Daniele Varrazzo
fd58f9105e Fixed read() exception propagation in copy_from
Close issue #412.
2016-03-08 05:12:06 +00:00
Daniele Varrazzo
ae87645c43 Merge branch 'setuptools' into maint_2_6 2016-03-08 04:34:41 +00:00
Daniele Varrazzo
40997d901b Fixed 'make sdist' to work with setuptools 2016-03-08 04:34:12 +00:00
Daniele Varrazzo
1f737c4d65 Merge branch 'msvc-2015-fix' into maint_2_6 2016-03-08 00:27:17 +00:00
Daniele Varrazzo
a355d48aeb Py 3.5 MSVC 2015 build fixed noted in news
Close issue #380.
2016-03-08 00:25:19 +00:00
Christian Ullrich
b6d1fbdfd1 Work around late initialization in distutils._msvccompiler. 2016-03-08 00:23:08 +00:00
Daniele Varrazzo
cbeea0f98f Merge branch 'setuptools' into maint_2_6 2016-03-07 10:39:03 +00:00
Daniele Varrazzo
88593602de setuptools in the news 2016-03-07 10:38:40 +00:00
Jason Erickson
ef09ebe62a Modify setup.py to support setuptools/wheel
To support creation of whl files for PyPI, setuptools need to be imported
instead of distutils.  Created try/except case to fall back to integrated
distutils if setuptools is not installed.
2016-03-05 13:22:39 -07:00
Daniele Varrazzo
2833d4f5ff Merge branch 'bug-382' into maint_2_6 2015-12-16 12:02:31 +00:00
Daniele Varrazzo
c20503544f Fixed race condition on import in errorcodes.lookup
Fixes #382.
2015-12-16 12:00:52 +00:00
Oleksandr Shulgin
ff4c52f435 Fix stale Dprintfs in pqpath.c referring to 'status' 2015-10-27 10:39:39 +00:00
Daniele Varrazzo
db9082b6e4 Decref the ssl module after importing 2015-10-01 17:02:43 +01:00
Daniele Varrazzo
78d6dca65d Bump to next version (uploading the docs) 2015-10-01 15:32:45 +01:00
Daniele Varrazzo
c076fc3a26 The wait_select callback can cancel a query using Ctrl-C
Fixes #333.
2015-10-01 15:27:31 +01:00
Daniele Varrazzo
347a64b979 Fixed PersistentConnectionPool on Python 3
Fixes ticket #348.
2015-10-01 14:44:56 +01:00
ClodoaldoPinto
a09efaf5a1 Typo correction 2015-10-01 14:31:51 +01:00
Daniele Varrazzo
1714bd9273 MSVC 2015 compiler support added to news file 2015-10-01 14:29:56 +01:00
Daniele Varrazzo
ca90fb2791 Merge branch 'msvc-2015-support' into maint_2_6 2015-10-01 13:36:15 +01:00
Photonios
9fd5def484 Fix for MSVC 2015: round has been added to this version 2015-10-01 13:35:58 +01:00
Photonios
4a6b31f56a Fix for MSVC 2015: isnan is supported in this version 2015-10-01 13:35:47 +01:00
Daniele Varrazzo
abf1f28c44 Report NotSupportedError for PGRES_COPY_BOTH and PGRES_SINGLE_TUPLE
Fixes #352.
2015-09-30 12:24:47 +01:00
Daniele Varrazzo
3e31fb359e Report the server response status on errors with no message
Suggested by Craig Ringer in pull request #353, should also give more
information for other cases we were reported on flaky servers (AWS,
digital ocean...), see bug #281.
2015-09-30 12:24:37 +01:00
Daniele Varrazzo
e707c3f657 Fixed build on Python 2.5 2015-06-15 10:31:14 +01:00
Daniele Varrazzo
b3c07fddb8 Fixed manifest trying to include Makefiles from build env 2015-06-15 03:43:11 +01:00
Daniele Varrazzo
c29dd8fffa Version bumped to release 2.6.1 2015-06-14 19:04:06 +01:00
Daniele Varrazzo
1aed1c6ecd Skip null array test on Postgres versions not supporting it 2015-06-14 19:04:04 +01:00
Daniele Varrazzo
6d2bd882ad Merge branch 'patch-328' into maint_2_6 2015-06-14 19:03:56 +01:00
Daniele Varrazzo
9021c90c07 Fixed compiler warnings about Py_ssize_t printf format 2015-06-14 19:03:01 +01:00
Jason Erickson
72c7374d8e Removed added Dprintf statements
Removed extra Dprintf statements added to trouble large objects
2015-06-08 14:05:05 -06:00
Jason Erickson
c4ffc0d940 Fix Windows 64bit lobject support for very (>2GB) large objects
The type 'long' with Windows Visual C is 32bits in size for both 32bit and 64bit platforms.  Changed type of variables that could be > 2GB from long to Py_ssize_t.
2015-06-08 11:37:23 -06:00
btubbs
fb487ff244 Notify example should pop the oldest message in conn.notifies, not the newest. 2015-06-02 17:07:19 +01:00
Pete Hollobon
526c9ea763 Change "non desiderable" to "undesirable" in docs
"desiderable" is considered obsolete
2015-06-02 13:03:11 +01:00
Daniele Varrazzo
57a4342946 Merge branch 'adapt-list-of-none' into maint_2_6 2015-06-02 12:41:10 +01:00
Daniele Varrazzo
6192649d25 Fixed adaptation of lists of None
Note: lists of lists of None are not supported yet.
2015-06-02 12:38:59 +01:00
Daniele Varrazzo
9ee15f9845 OpenSSL deadlock fix noted in NEWSfile 2015-05-03 12:27:27 +01:00
Jan Urbański
60fe90d531 Make sure libcrypto threadsafety callbacks are properly set up
Multithreaded programs using libcrypto (part of OpenSSL) need to set up
callbacks to ensure safe execution. Both Python and libpq set up those
callbacks, which might lead to a conflict.

To avoid leaving dangling function pointers when being unloaded, libpq sets up
and removes the callbacks every time a SSL connection it opened and closed. If
another Python thread is performing unrelated SSL operations (like connecting
to a HTTPS server), this might lead to deadlocks, as described in
http://www.postgresql.org/message-id/871tlzrlkq.fsf@wulczer.org

Even if the problem will be remediated in libpq, it's still useful to have it
fixed in psycopg2. The solution is to use Python's own libcrypto callbacks and
completely disable handling them in libpq.
2015-05-03 12:19:50 +01:00
Daniele Varrazzo
76ac3ec34e Improve docs about connection's with only closing the transaction 2015-05-03 11:59:06 +01:00
Daniele Varrazzo
a70a541e0b Unlock the connection after PQflush error
Apparently this has never happened... anyway the code path was wrong.

Fixes #294.
2015-05-03 11:58:16 +01:00
Daniele Varrazzo
8739484b61 Added makefile target to upload docs 2015-05-03 10:25:51 +01:00
Daniele Varrazzo
b77a8033d3 Added note about table names to be escaped in copy_*() methods. 2015-05-03 10:22:14 +01:00
Hyunjun Kim
00946ae7f4 Fix several typos 2015-05-03 10:00:11 +01:00
Daniele Varrazzo
862f47040c Fix to MinTimeLoggingCursor.callproc() noted in NEWSfile 2015-05-03 09:58:45 +01:00
andrew deryabin
6a62b4fa1d Fixed MinTimeLoggingCursor.callproc() 2015-05-03 09:55:40 +01:00
Daniele Varrazzo
b2734c2cbd Wordsmith on connection.set_session()
Fixes #310.
2015-05-03 09:42:32 +01:00