8000 Fix possible cache invalidation failure in ReceiveSharedInvalidMessages. · postgrespro/postgres_cluster@0f928a8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0f928a8

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 o 10000 f 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 3727afa commit 0f928a8

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
@@ -91,10 +91,10 @@ ReceiveSharedInvalidMessages(
9191
/* Deal with any messages still pending from an outer recursion */
9292
while (nextmsg < nummsgs)
9393
{
94-
SharedInvalidationMessage *msg = &messages[nextmsg++];
94+
SharedInvalidationMessage msg = messages[nextmsg++];
9595

9696
SharedInvalidMessageCounter++;
97-
invalFunction(msg);
97+
invalFunction(&msg);
9898
}
9999

100100
do
@@ -121,10 +121,10 @@ ReceiveSharedInvalidMessages(
121121

122122
while (nextmsg < nummsgs)
123123
{
124-
SharedInvalidationMessage *msg = &messages[nextmsg++];
124+
SharedInvalidationMessage msg = messages[nextmsg++];
125125

126126
SharedInvalidMessageCounter++;
127-
invalFunction(msg);
127+
invalFunction(&msg);
128128
}
129129

130130
/*

0 commit comments

Comments
 (0)
0