Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit42d7074

Browse files
committed
shm_mq: Fix detach race condition.
Commit34db06e adopted a lock-freedesign for shm_mq.c, but it introduced a race condition that couldlose messages. When shm_mq_receive_bytes() detects that the other endhas detached, it must make sure that it has seen the final version ofmq_bytes_written, or it might miss a message sent before detaching.Thomas MunroDiscussion:https://postgr.es/m/CAEepm%3D2myZ4qxpt1a%3DC%2BwEv3o188K13K3UvD-44FK0SdAzHy%2Bw%40mail.gmail.com
1 parent2f3e234 commit42d7074

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

‎src/backend/storage/ipc/shm_mq.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,19 @@ shm_mq_receive_bytes(shm_mq_handle *mqh, Size bytes_needed, bool nowait,
10581058
* detached.
10591059
*/
10601060
if (mq->mq_detached)
1061+
{
1062+
/*
1063+
* If the writer advanced mq_bytes_written and then set
1064+
* mq_detached, we might not have read the final value of
1065+
* mq_bytes_written above. Insert a read barrier and then check
1066+
* again if mq_bytes_written has advanced.
1067+
*/
1068+
pg_read_barrier();
1069+
if (written!=pg_atomic_read_u64(&mq->mq_bytes_written))
1070+
continue;
1071+
10611072
returnSHM_MQ_DETACHED;
1073+
}
10621074

10631075
/*
10641076
* We didn't get enough data to satisfy the request, so mark any data

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp