Skip to content

Commit e084b14

Browse files
committed
Minor robustness improvements for isolationtester.
Notice and complain about PQcancel() failures. Also, don't dump core if an error PGresult doesn't contain severity and message subfields, as it might not if it was generated by libpq itself. (We have a longstanding TODO item to improve that, but in the meantime isolationtester had better cope.) I tripped across the latter item while investigating a trouble report on buildfarm member spoonbill. As for the former, there's no evidence that PQcancel failure is actually involved in spoonbill's problem, but it still seems like a bad idea to ignore an error return code.
1 parent 73c1227 commit e084b14

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

src/test/isolation/isolationtester.c

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,8 @@ run_permutation(TestSpec * testspec, int nsteps, Step ** steps)
572572
{
573573
char buf[256];
574574

575-
PQcancel(cancel, buf, sizeof(buf));
575+
if (!PQcancel(cancel, buf, sizeof(buf)))
576+
fprintf(stderr, "PQcancel failed: %s\n", buf);
576577

577578
/* Be sure to consume the error message. */
578579
while ((res = PQgetResult(conn)) != NULL)
@@ -764,14 +765,26 @@ try_complete_step(Step * step, int flags)
764765
printf("WARNING: this step had a leftover error message\n");
765766
printf("%s\n", step->errormsg);
766767
}
767-
/* Detail may contain xid values, so just show primary. */
768-
step->errormsg = malloc(5 +
769-
strlen(PQresultErrorField(res, PG_DIAG_SEVERITY)) +
770-
strlen(PQresultErrorField(res,
771-
PG_DIAG_MESSAGE_PRIMARY)));
772-
sprintf(step->errormsg, "%s: %s",
773-
PQresultErrorField(res, PG_DIAG_SEVERITY),
774-
PQresultErrorField(res, PG_DIAG_MESSAGE_PRIMARY));
768+
769+
/*
770+
* Detail may contain XID values, so we want to just show
771+
* primary. Beware however that libpq-generated error results
772+
* may not contain subfields, only an old-style message.
773+
*/
774+
{
775+
const char *sev = PQresultErrorField(res,
776+
PG_DIAG_SEVERITY);
777+
const char *msg = PQresultErrorField(res,
778+
PG_DIAG_MESSAGE_PRIMARY);
779+
780+
if (sev && msg)
781+
{
782+
step->errormsg = malloc(5 + strlen(sev) + strlen(msg));
783+
sprintf(step->errormsg, "%s: %s", sev, msg);
784+
}
785+
else
786+
step->errormsg = strdup(PQresultErrorMessage(res));
787+
}
775788
break;
776789
default:
777790
printf("unexpected result status: %s\n",

0 commit comments

Comments
 (0)