diff --git a/NEWS b/NEWS index b229795d..e0dd56e8 100644 --- a/NEWS +++ b/NEWS @@ -27,6 +27,8 @@ What's new in psycopg 2.5.3 (:ticket:`#203`). - 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`). - Fixed possible segfault in named cursors creation. - It is now possible to call `get_transaction_status()` on closed connections. - Fixed debug build on Windows, thanks to James Emerton. diff --git a/psycopg/pqpath.c b/psycopg/pqpath.c index 86709657..0e9481a5 100644 --- a/psycopg/pqpath.c +++ b/psycopg/pqpath.c @@ -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) {