Re: failures in t/031_recovery_conflict.pl on CI
Andres Freund <andres@anarazel.de>
From: Andres Freund <andres@anarazel.de>
To: pgsql-hackers@postgresql.org, Thomas Munro <thomas.munro@gmail.com>
Date: 2022-04-09T23:10:02Z
Lists: pgsql-hackers
Hi,
On 2022-04-09 15:00:54 -0700, Andres Freund wrote:
> What are we expecting to wake the startup process up, once it does
> SendRecoveryConflictWithBufferPin()?
>
> It's likely not the problem here, because we never seem to have even reached
> that path, but afaics once we've called disable_all_timeouts() at the bottom
> of ResolveRecoveryConflictWithBufferPin() and then re-entered
> ResolveRecoveryConflictWithBufferPin(), and go into the "We're already behind,
> so clear a path as quickly as possible." path, there's no guarantee for any
> timeout to be pending anymore?
>
> If there's either no backend that we're still conflicting with (an entirely
> possible race condition), or if there's e.g. a snapshot or database conflict,
> there's afaics nobody setting the startup processes' latch.
It's not that (although I still suspect it's a problem). It's a self-deadlock,
because StandbyTimeoutHandler(), which ResolveRecoveryConflictWithBufferPin()
*explicitly enables*, calls SendRecoveryConflictWithBufferPin(). Which does
CancelDBBackends(). Which ResolveRecoveryConflictWithBufferPin() also calls,
if the deadlock timeout is reached.
To make it easier to hit, I put a pg_usleep(10000) in CancelDBBackends(), and boom:
(gdb) bt
#0 __futex_abstimed_wait_common64 (futex_word=futex_word@entry=0x7fd4cb001138, expected=expected@entry=0, clockid=clockid@entry=0,
abstime=abstime@entry=0x0, private=<optimized out>, cancel=cancel@entry=true) at ../sysdeps/nptl/futex-internal.c:87
#1 0x00007fd4ce5a215b in __GI___futex_abstimed_wait_cancelable64 (futex_word=futex_word@entry=0x7fd4cb001138, expected=expected@entry=0,
clockid=clockid@entry=0, abstime=abstime@entry=0x0, private=<optimized out>) at ../sysdeps/nptl/futex-internal.c:123
#2 0x00007fd4ce59e44f in do_futex_wait (sem=sem@entry=0x7fd4cb001138, abstime=0x0, clockid=0) at sem_waitcommon.c:112
#3 0x00007fd4ce59e4e8 in __new_sem_wait_slow64 (sem=0x7fd4cb001138, abstime=0x0, clockid=0) at sem_waitcommon.c:184
#4 0x00007fd4cf20d823 in PGSemaphoreLock (sema=0x7fd4cb001138) at pg_sema.c:327
#5 0x00007fd4cf2dd675 in LWLockAcquire (lock=0x7fd4cb001600, mode=LW_EXCLUSIVE) at /home/andres/src/postgresql/src/backend/storage/lmgr/lwlock.c:1324
#6 0x00007fd4cf2c36e7 in CancelDBBackends (databaseid=0, sigmode=PROCSIG_RECOVERY_CONFLICT_BUFFERPIN, conflictPending=false)
at /home/andres/src/postgresql/src/backend/storage/ipc/procarray.c:3638
#7 0x00007fd4cf2cc579 in SendRecoveryConflictWithBufferPin (reason=PROCSIG_RECOVERY_CONFLICT_BUFFERPIN)
at /home/andres/src/postgresql/src/backend/storage/ipc/standby.c:846
#8 0x00007fd4cf2cc69d in StandbyTimeoutHandler () at /home/andres/src/postgresql/src/backend/storage/ipc/standby.c:911
#9 0x00007fd4cf4e68d7 in handle_sig_alarm (postgres_signal_arg=14) at /home/andres/src/postgresql/src/backend/utils/misc/timeout.c:421
#10 <signal handler called>
#11 0x00007fd4cddfffc4 in __GI___select (nfds=0, readfds=0x0, writefds=0x0, exceptfds=0x0, timeout=0x7ffc6e5561c0) at ../sysdeps/unix/sysv/linux/select.c:71
#12 0x00007fd4cf52ea2a in pg_usleep (microsec=10000) at /home/andres/src/postgresql/src/port/pgsleep.c:56
#13 0x00007fd4cf2c36f1 in CancelDBBackends (databaseid=0, sigmode=PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK, conflictPending=false)
at /home/andres/src/postgresql/src/backend/storage/ipc/procarray.c:3640
#14 0x00007fd4cf2cc579 in SendRecoveryConflictWithBufferPin (reason=PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK)
at /home/andres/src/postgresql/src/backend/storage/ipc/standby.c:846
#15 0x00007fd4cf2cc50f in ResolveRecoveryConflictWithBufferPin () at /home/andres/src/postgresql/src/backend/storage/ipc/standby.c:820
#16 0x00007fd4cf2a996f in LockBufferForCleanup (buffer=43) at /home/andres/src/postgresql/src/backend/storage/buffer/bufmgr.c:4336
#17 0x00007fd4ceec911c in XLogReadBufferForRedoExtended (record=0x7fd4d106a618, block_id=0 '\000', mode=RBM_NORMAL, get_cleanup_lock=true, buf=0x7ffc6e556394)
at /home/andres/src/postgresql/src/backend/access/transam/xlogutils.c:427
#18 0x00007fd4cee1aa41 in heap_xlog_prune (record=0x7fd4d106a618) at /home/andres/src/postgresql/src/backend/access/heap/heapam.c:8634
it's reproducible on linux.
I'm lacking words I dare to put in an email to describe how bad an idea it is
to call CancelDBBackends() from within a timeout function, particularly when
the function enabling the timeout also calls that function itself. Before
disabling timers.
I ...
Greetings,
Andres Freund
Commits
-
Disable 031_recovery_conflict.pl until after minor releases.
- 390b489eff76 10.21 landed
- 4caa29414d60 11.16 landed
- 1e1542833e8c 12.11 landed
- 6348e4685068 13.7 landed
- 55e5a5e0fa16 14.3 landed
-
Temporarily skip recovery deadlock test in back branches.
- 441fa7a63ad4 10.21 landed
- fb965ab0f641 11.16 landed
- 26f9e21cb63e 12.11 landed
- 4e39957e6eb5 13.7 landed
- f40d362a667f 14.3 landed
-
Backpatch addition of pump_until() more completely.
- 47f47a8d4738 11.16 landed
- fbf659bc4040 12.11 landed
- 6ab90d215afc 13.7 landed
- 7fa95bb0ac8e 14.3 landed
-
Fix timing issue in deadlock recovery conflict test.
- 3197e0f5ae9d 10.21 landed
- 7a1267f9fe74 11.16 landed
- 512d76f6dbda 12.11 landed
- 8a3a8d9f103e 13.7 landed
- 5136967f1eb1 14.3 landed
- 9e6b7b45ca92 15.0 landed
-
Backpatch 031_recovery_conflict.pl.
- b1f35a36e6d5 10.21 landed
- 25d5494e2841 11.16 landed
- a5ede13916f3 12.11 landed
- 0446d3bf3909 13.7 landed
- f74496dd611e 14.3 landed
-
Fix possibility of self-deadlock in ResolveRecoveryConflictWithBufferPin().
- cbc47ad7ef60 10.21 landed
- 9cda785b4ea3 11.16 landed
- edfc03ec91f2 12.11 landed
- 57c5ad168be1 13.7 landed
- 9ab3b2bdbb5d 14.3 landed
- 8f1537d10e83 15.0 landed
-
Backpatch addition of wait_for_log(), pump_until().
- e8a0cf9b20a1 10.21 landed
- 2adb8debe5aa 11.16 landed
- 90abe1e17f9d 13.7 landed
- 5c8b14a71d31 12.11 landed
- 5ab8e8014801 14.3 landed
-
Add tests for recovery deadlock conflicts.
- 21e184403bf9 15.0 landed
-
Phase 3 of pgindent updates.
- 382ceffdf7f6 10.0 cited