Skip to content

Commit 3ada1fa

Browse files
committed
Fix possible cache invalidation failure in ReceiveSharedInvalidMessages.
Commit fad153e modified sinval.c to reduce the number of calls into sinvaladt.c (which require taking a shared lock) by keeping a local buffer of collected-but-not-yet-processed messages. However, if processing of the last message in a batch resulted in a recursive call to ReceiveSharedInvalidMessages, we could overwrite that message with a new one while the outer invalidation function was still working on it. This would be likely to lead to invalidation of the wrong cache entry, allowing subsequent processing to use stale cache data. The fix is just to make a local copy of each message while we're processing it. Spotted by Andres Freund. Back-patch to 8.4 where the bug was introduced.
1 parent 70debcf commit 3ada1fa

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/backend/storage/ipc/sinval.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ ReceiveSharedInvalidMessages(
8888
/* Deal with any messages still pending from an outer recursion */
8989
while (nextmsg < nummsgs)
9090
{
91-
SharedInvalidationMessage *msg = &messages[nextmsg++];
91+
SharedInvalidationMessage msg = messages[nextmsg++];
9292

93-
invalFunction(msg);
93+
invalFunction(&msg);
9494
}
9595

9696
do
@@ -116,9 +116,9 @@ ReceiveSharedInvalidMessages(
116116

117117
while (nextmsg < nummsgs)
118118
{
119-
SharedInvalidationMessage *msg = &messages[nextmsg++];
119+
SharedInvalidationMessage msg = messages[nextmsg++];
120120

121-
invalFunction(msg);
121+
invalFunction(&msg);
122122
}
123123

124124
/*

0 commit comments

Comments
 (0)