Skip to content

Commit 97fb88e

Browse files
committed
Fix isolationtester race condition for notices sent before blocking.
If a test sends a notice just before blocking, it's possible on slow machines for isolationtester to detect the blocked state before it's consumed the notice. (For this to happen, the notice would have to arrive after isolationtester has waited for data for 10ms, so on fast/lightly-loaded machines it's hard to reproduce the failure.) But, if we have seen the backend as blocked, it's certainly already sent any notices it's going to send. Therefore, one more round of PQconsumeInput and PQisBusy should be enough to collect and process any such notices. Back-patch of 3071763 into v12. We're still discussing whether to back-patch this further and/or back-patch some other recent isolationtester fixes, but this much is provably necessary to make the test cases added by 27cc7cd stable in v12. Discussion: https://postgr.es/m/14616.1564251339@sss.pgh.pa.us Discussion: https://postgr.es/m/E1i7IqC-0000Uc-5H@gemulon.postgresql.org
1 parent 84bb33c commit 97fb88e

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/test/isolation/isolationtester.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,28 @@ try_complete_step(Step *step, int flags)
764764

765765
if (waiting) /* waiting to acquire a lock */
766766
{
767+
/*
768+
* Since it takes time to perform the lock-check query,
769+
* some data --- notably, NOTICE messages --- might have
770+
* arrived since we looked. We must call PQconsumeInput
771+
* and then PQisBusy to collect and process any such
772+
* messages. In the (unlikely) case that PQisBusy then
773+
* returns false, we might as well go examine the
774+
* available result.
775+
*/
776+
if (!PQconsumeInput(conn))
777+
{
778+
fprintf(stderr, "PQconsumeInput failed: %s\n",
779+
PQerrorMessage(conn));
780+
exit(1);
781+
}
782+
if (!PQisBusy(conn))
783+
break;
784+
785+
/*
786+
* conn is still busy, so conclude that the step really is
787+
* waiting.
788+
*/
767789
if (!(flags & STEP_RETRY))
768790
printf("step %s: %s <waiting ...>\n",
769791
step->name, step->sql);

0 commit comments

Comments
 (0)