diff --git a/NEWS b/NEWS index c834d78d..52cbe225 100644 --- a/NEWS +++ b/NEWS @@ -22,6 +22,8 @@ What's new in psycopg 2.4.7 failing to connect (from :ticket:`#192` discussion). - 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 overflow opening a lobject with an oid not fitting in a signed int (:ticket:`#203`). - Fixed possible segfault in named cursors creation. diff --git a/psycopg/pqpath.c b/psycopg/pqpath.c index 7290ad33..76032ec8 100644 --- a/psycopg/pqpath.c +++ b/psycopg/pqpath.c @@ -388,12 +388,20 @@ pq_complete_error(connectionObject *conn, PGresult **pgres, char **error) { Dprintf("pq_complete_error: pgconn = %p, pgres = %p, error = %s", conn->pgconn, *pgres, *error ? *error : "(null)"); - if (*pgres != NULL) + if (*pgres != NULL) { pq_raise(conn, NULL, *pgres); - else if (*error != NULL) { - PyErr_SetString(OperationalError, *error); } else { - PyErr_SetString(OperationalError, "unknown error"); + 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; } IFCLEARPGRES(*pgres); if (*error) {