summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2014-05-05 18:43:55 +0000
committerTom Lane2014-05-05 18:43:55 +0000
commit3ada1fab8bf9ba001fcb095d66914f3f1f34711f (patch)
tree068d17c12b4a4026748fd13218020bfa6b580ea7
parent70debcf09563a82c85b3221d402b4e8a07f4367e (diff)
Fix possible cache invalidation failure in ReceiveSharedInvalidMessages.
Commit fad153ec45299bd4d4f29dec8d9e04e2f1c08148 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.
-rw-r--r--src/backend/storage/ipc/sinval.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/backend/storage/ipc/sinval.c b/src/backend/storage/ipc/sinval.c
index 9028ede2eb0..4b3d42348f1 100644
--- a/src/backend/storage/ipc/sinval.c
+++ b/src/backend/storage/ipc/sinval.c
@@ -88,9 +88,9 @@ ReceiveSharedInvalidMessages(
/* Deal with any messages still pending from an outer recursion */
while (nextmsg < nummsgs)
{
- SharedInvalidationMessage *msg = &messages[nextmsg++];
+ SharedInvalidationMessage msg = messages[nextmsg++];
- invalFunction(msg);
+ invalFunction(&msg);
}
do
@@ -116,9 +116,9 @@ ReceiveSharedInvalidMessages(
while (nextmsg < nummsgs)
{
- SharedInvalidationMessage *msg = &messages[nextmsg++];
+ SharedInvalidationMessage msg = messages[nextmsg++];
- invalFunction(msg);
+ invalFunction(&msg);
}
/*