Fix losing a sinval catchup signal that arrives during catchup If a new catchup signal arrives while we're still processing a previous catchup signal, the new signal might be lost:
When a backend falls far behind in the shared invalidation queue, SICleanupQueue() sets its "signaled" flag, and sends it PROCSIG_CATCHUP_INTERRUPT, which sets the catchupInterruptPending flag in the receiving backend. There was a race condition in how ReceiveSharedInvalidMessages() cleared catchupInterruptPending and "signaled". It cleared "signaled" first, after consuming all the messages, and catchupInterruptPending only after that. If a new catchup signal arrived after the "signaled" flag was cleared in SIGetDataEntries(), but before clearing catchupInterruptPending, the backend could be left with its "signaled" flag set but catchupInterruptPending not set. As a result, other backends would not send it any more catchup signals, but it would not wake up to consume the messages until AcceptInvalidationMessages() was called for some other reason, typically when it next ran a query. To fix, reset catchupInterruptPending only if "signaled" was not concurrently re-armed. Move the responsibility for resetting it into SICleanupQueue() itself, because it already holds the lock needed to read "signaled". No backpatching, since we have no reports from the field about this, and the consequences are not that severe. Reviewed-by: Shihao Zhong <[email protected]> Reviewed-by: Ayush Tiwari <[email protected]> Discussion: https://www.postgresql.org/message-id/[email protected] Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/3b249c728fd126c684be77ae834cb7eaa38d0962 Modified Files -------------- src/backend/storage/ipc/sinval.c | 16 +++++++++------- src/backend/storage/ipc/sinvaladt.c | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 7 deletions(-)
