1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-01-18 04:58:51 +02:00

Improve error message when PQgetCancel() returns NULL.

There is not a lot to be done in this case since it looks like PostgreSQL disconnected while the query was running, but at least improve the error message and remove the assert, which indicates a coding error.
This commit is contained in:
David Steele 2020-12-01 15:15:35 -05:00
parent d1d25c710d
commit ffc50719d9
3 changed files with 25 additions and 2 deletions

View File

@ -203,7 +203,10 @@ pgClientQuery(PgClient *this, const String *query)
if (busy)
{
PGcancel *cancel = PQgetCancel(this->connection);
CHECK(cancel != NULL);
// If cancel is NULL then more than likely the server process crashed or disconnected
if (cancel == NULL)
THROW_FMT(DbQueryError, "unable to cancel query '%s': connection was lost", strZ(query));
TRY_BEGIN()
{

View File

@ -216,7 +216,8 @@ Shim for PQgetCancel()
PGcancel *
PQgetCancel(PGconn *conn)
{
return (PGcancel *)harnessPqScriptRun(HRNPQ_GETCANCEL, NULL, (HarnessPq *)conn);
HarnessPq *harnessPq = harnessPqScriptRun(HRNPQ_GETCANCEL, NULL, (HarnessPq *)conn);
return harnessPq->resultNull ? NULL : (PGcancel *)harnessPq;
}
/***********************************************************************************************************************************

View File

@ -189,6 +189,25 @@ testRun(void)
TEST_ERROR(pgClientQuery(client, query), DbQueryError, "unable to cancel query 'select pg_sleep(3000)': test error");
#endif
// -------------------------------------------------------------------------------------------------------------------------
#ifndef HARNESS_PQ_REAL
TEST_TITLE("PQgetCancel() returns NULL");
harnessPqScriptSet((HarnessPq [])
{
{.function = HRNPQ_SENDQUERY, .param = "[\"select 1\"]", .resultInt = 1},
{.function = HRNPQ_CONSUMEINPUT, .sleep = 600},
{.function = HRNPQ_ISBUSY, .resultInt = 1},
{.function = HRNPQ_CONSUMEINPUT},
{.function = HRNPQ_ISBUSY, .resultInt = 1},
{.function = HRNPQ_GETCANCEL, .resultNull = true},
{.function = NULL}
});
TEST_ERROR(
pgClientQuery(client, STRDEF("select 1")), DbQueryError, "unable to cancel query 'select 1': connection was lost");
#endif
// Execute do block and raise notice
// -------------------------------------------------------------------------------------------------------------------------
#ifndef HARNESS_PQ_REAL