diff --git a/connection.c b/connection.c index 154ada9..1673a8a 100644 --- a/connection.c +++ b/connection.c @@ -3065,6 +3065,13 @@ inolog("Discarded the first SAVEPOINT\n"); } } + /* + * Leave if socket has been dropped due to a dead + * connection. + */ + if (!self->sock) + break; + if (QR_command_successful(res)) QR_set_rstatus(res, PORES_COMMAND_OK); QR_set_command(res, cmdbuffer); @@ -3078,13 +3085,12 @@ inolog("Discarded the first SAVEPOINT\n"); * backend may produce more than one result for some * commands we need to poll until clear so we send an * empty query, and keep reading out of the pipe until - * an 'I' is received + * an 'I' is received. */ - - if (empty_reqs == 0) + if (self->sock && empty_reqs == 0) { - SOCK_put_string(sock, "Q "); - SOCK_flush_output(sock); + SOCK_put_string(self->sock, "Q "); + SOCK_flush_output(self->sock); empty_reqs++; } } @@ -3313,7 +3319,7 @@ mylog("!!! copydata len=%d\n", response_length); break; } - if (SOCK_get_errcode(sock) != 0) + if (self->sock && SOCK_get_errcode(self->sock) != 0) break; if (CONN_DOWN == self->status) break; @@ -3328,7 +3334,7 @@ mylog("!!! copydata len=%d\n", response_length); } cleanup: - if (SOCK_get_errcode(sock) != 0) + if (self->sock && SOCK_get_errcode(self->sock) != 0) { if (0 == CC_get_errornumber(self)) CC_set_error(self, CONNECTION_COMMUNICATION_ERROR, "Communication error while sending query", func);