mirror of
https://github.com/postgres/postgres.git
synced 2025-10-15 05:46:52 +03:00
pgbench: Fix error reporting in readCommandResponse().
pgbench uses readCommandResponse() to process server responses. When readCommandResponse() encounters an error during a call to PQgetResult() to fetch the current result, it attempts to report it with an additional error message from PQerrorMessage(). However, previously, this extra error message could be lost or become incorrect. The cause was that after fetching the current result (and detecting an error), readCommandResponse() called PQgetResult() again to peek at the next result. This second call could overwrite the libpq connection's error message before the original error was reported, causing the error message retrieved from PQerrorMessage() to be lost or overwritten. This commit fixes the issue by updating readCommandResponse() to use PQresultErrorMessage() instead of PQerrorMessage() to retrieve the error message generated when the PQgetResult() for the current result causes an error, ensuring the correct message is reported. Backpatch to all supported versions. Author: Yugo Nagata <nagata@sraoss.co.jp> Reviewed-by: Chao Li <lic@highgo.com> Reviewed-by: Fujii Masao <masao.fujii@gmail.com> Discussion: https://postgr.es/m/20250925110940.ebacc31725758ec47d5432c6@sraoss.co.jp Backpatch-through: 13
This commit is contained in:
@@ -3356,7 +3356,7 @@ readCommandResponse(CState *st, MetaCommand meta, char *varprefix)
|
|||||||
st->num_syncs--;
|
st->num_syncs--;
|
||||||
if (st->num_syncs == 0 && PQexitPipelineMode(st->con) != 1)
|
if (st->num_syncs == 0 && PQexitPipelineMode(st->con) != 1)
|
||||||
pg_log_error("client %d failed to exit pipeline mode: %s", st->id,
|
pg_log_error("client %d failed to exit pipeline mode: %s", st->id,
|
||||||
PQerrorMessage(st->con));
|
PQresultErrorMessage(res));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PGRES_NONFATAL_ERROR:
|
case PGRES_NONFATAL_ERROR:
|
||||||
@@ -3366,7 +3366,7 @@ readCommandResponse(CState *st, MetaCommand meta, char *varprefix)
|
|||||||
if (canRetryError(st->estatus))
|
if (canRetryError(st->estatus))
|
||||||
{
|
{
|
||||||
if (verbose_errors)
|
if (verbose_errors)
|
||||||
commandError(st, PQerrorMessage(st->con));
|
commandError(st, PQresultErrorMessage(res));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
/* fall through */
|
/* fall through */
|
||||||
@@ -3375,7 +3375,7 @@ readCommandResponse(CState *st, MetaCommand meta, char *varprefix)
|
|||||||
/* anything else is unexpected */
|
/* anything else is unexpected */
|
||||||
pg_log_error("client %d script %d aborted in command %d query %d: %s",
|
pg_log_error("client %d script %d aborted in command %d query %d: %s",
|
||||||
st->id, st->use_file, st->command, qrynum,
|
st->id, st->use_file, st->command, qrynum,
|
||||||
PQerrorMessage(st->con));
|
PQresultErrorMessage(res));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user