Skip to content

Commit

Permalink
Close a connection if PQexec returned NULL
Browse files Browse the repository at this point in the history
This happens for Socket connections, not for TCP ones, where a result
containing an error is returned and correctly handled by pq_raise()

Closes ticket psycopg#196 but not psycopg#192: poll() still doesn't change the
connection closed.
  • Loading branch information
dvarrazzo committed Mar 6, 2014
1 parent f597c36 commit d1e1243
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions NEWS
Expand Up @@ -10,6 +10,8 @@ What's new in psycopg 2.5.3
Adam Petrovich for the bug report and diagnosis.
- Don't segfault using poorly defined cursor subclasses which forgot to call
the superclass init (:ticket:`#195`).
- Mark the connection closed when a Socket connection is broken, as it
happens for TCP connections instead (:ticket:`#196`).
- It is now possible to call `get_transaction_status()` on closed connections.
- Fixed debug build on Windows, thanks to James Emerton.

Expand Down
16 changes: 12 additions & 4 deletions psycopg/pqpath.c
Expand Up @@ -417,10 +417,18 @@ pq_complete_error(connectionObject *conn, PGresult **pgres, char **error)
pq_raise(conn, NULL, pgres);
/* now *pgres is null */
}
else if (*error != NULL) {
PyErr_SetString(OperationalError, *error);
} else {
PyErr_SetString(OperationalError, "unknown error");
else {
if (*error != NULL) {
PyErr_SetString(OperationalError, *error);
} else {
PyErr_SetString(OperationalError, "unknown error");
}
/* Trivia: with a broken socket connection PQexec returns NULL, so we
* end up here. With a TCP connection we get a pgres with an error
* instead, and the connection gets closed in the pq_raise call above
* (see ticket #196)
*/
conn->closed = 2;
}

if (*error) {
Expand Down

0 comments on commit d1e1243

Please sign in to comment.