diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c index 1e1806fad9..25141edd84 100644 --- a/src/bin/pgbench/pgbench.c +++ b/src/bin/pgbench/pgbench.c @@ -3683,7 +3683,7 @@ threadRun(void *arg) sock = PQsocket(st->con); if (sock < 0) { - fprintf(stderr, "bad socket: %s\n", strerror(errno)); + fprintf(stderr, "bad socket: %s", PQerrorMessage(st->con)); goto done; } @@ -3751,11 +3751,21 @@ threadRun(void *arg) Command **commands = sql_files[st->use_file]; int prev_ecnt = st->ecnt; - if (st->con && (FD_ISSET(PQsocket(st->con), &input_mask) - || commands[st->state]->type == META_COMMAND)) + if (st->con) { - if (!doCustom(thread, st, &result->conn_time, logfile, &aggs)) - remains--; /* I've aborted */ + int sock = PQsocket(st->con); + + if (sock < 0) + { + fprintf(stderr, "bad socket: %s", PQerrorMessage(st->con)); + goto done; + } + if (FD_ISSET(sock, &input_mask) || + commands[st->state]->type == META_COMMAND) + { + if (!doCustom(thread, st, &result->conn_time, logfile, &aggs)) + remains--; /* I've aborted */ + } } if (st->ecnt > prev_ecnt && commands[st->state]->type == META_COMMAND)