8000 Make WL_POSTMASTER_DEATH level-triggered on kqueue builds. · postgres/postgres@b94109c · GitHub
[go: up one dir, main page]

Skip to content
{"payload":{"commit":{"oid":"b94109ce375b137f235149bfba3559c69f4573e7","url":"/postgres/postgres/commit/b94109ce375b137f235149bfba3559c69f4573e7","authoredDate":"2020-10-15T11:31:20.000+13:00","committedDate":"2020-10-15T11:41:58.000+13:00","shortMessage":null,"shortMessageMarkdown":"\u003cdiv\u003eMake WL_POSTMASTER_DEATH level-triggered on kqueue builds.\u003c/div\u003e","shortMessageMarkdownLink":null,"bodyMessageHtml":"If WaitEventSetWait() reports that the postmaster has gone away, later\ncalls to WaitEventSetWait() should continue to report that. Otherwise\nfurther waits that occur in the proc_exit() path after we already\nnoticed the postmaster's demise could block forever.\n\nBack-patch to 13, where the kqueue support landed.\n\nReported-by: Tom Lane \u0026lt;tgl@sss.pgh.pa.us\u0026gt;\nDiscussion: \u003ca href=\"https://postgr.es/m/3624029.1602701929%40sss.pgh.pa.us\" rel=\"nofollow\"\u003ehttps://postgr.es/m/3624029.1602701929%40sss.pgh.pa.us\u003c/a\u003e","authors":[{"login":"macdice","displayName":"Thomas Munro","avatarUrl":"https://avatars.githubusercontent.com/u/150350?v=4","path":"/macdice","isGitHub":false}],"committerAttribution":false,"committer":{"login":"macdice","displayName":"Thomas Munro","avatarUrl":"https://avatars.githubusercontent.com/u/150350?v=4","path":"/macdice","isGitHub":false},"parents":["a04daa97a4339c38e304cd6164d37da540d665a8"],"globalRelayId":"MDY6Q29tbWl0OTI3NDQyOmI5NDEwOWNlMzc1YjEzN2YyMzUxNDliZmJhMzU1OWM2OWY0NTczZTc=","sha1":"a04daa97a4339c38e304cd6164d37da540d665a8","sha2":"b94109ce375b137f235149bfba3559c69f4573e7"},"currentUser":null,"repo":{"id":927442,"defaultBranch":"master","name":"postgres","ownerLogin":"postgres","currentUserCanPush":false,"isFork":false,"isEmpty":false,"createdAt":"2010-09-21T11:35:45.000Z","ownerAvatar":"https://avatars.githubusercontent.com/u/177543?v=4","public":true,"private":false,"isOrgOwned":true},"diffEntryData":[{"diffLines":[{"stylingDirective":null,"type":"HUNK","blobLineNumber":1491,"text":"@@ -1492,7 +1492,10 @@ WaitEventSetWaitBlock(WaitEventSet *set, int cur_timeout,","html":"@@ -1492,7 +1492,10 @@ WaitEventSetWaitBlock(WaitEventSet *set, int cur_timeout,","displayNoNewLineWarning":false,"position":0,"left":1491,"right":1491},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1492,"text":" \t\ttimeout_p = \u0026timeout;","html":" \t\t\u003cspan class=pl-s1\u003etimeout_p\u003c/span\u003e \u003cspan class=pl-c1\u003e=\u003c/span\u003e \u003cspan class=pl-c1\u003e\u0026amp;\u003c/span\u003e\u003cspan class=pl-s1\u003etimeout\u003c/span\u003e;","displayNoNewLineWarning":false,"position":1,"left":1492,"right":1492},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1493,"text":" \t}","html":" \t}","displayNoNewLineWarning":false,"position":2,"left":1493,"right":1493},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1494,"text":" ","html":"\u003cbr\u003e","displayNoNewLineWarning":false,"position":3,"left":1494,"right":1494},{"stylingDirective":null,"type":"DELETION","blobLineNumber":1495,"text":"-\t/* Report events discovered by WaitEventAdjustKqueue(). */","html":"-\t\u003cspan class=pl-c\u003e/* Report events discovered by WaitEventAdjustKqueue(). */\u003c/span\u003e","displayNoNewLineWarning":false,"position":4,"left":1495,"right":1494},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1495,"text":"+\t/*","html":"+\t\u003cspan class=pl-c\u003e/*\u003c/span\u003e","displayNoNewLineWarning":false,"position":5,"left":1495,"right":1495},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1496,"text":"+\t * Report postmaster events discovered by WaitEventAdjustKqueue() or an","html":"+\u003cspan class=pl-c\u003e\t * Report postmaster events discovered by WaitEventAdjustKqueue() or an\u003c/span\u003e","displayNoNewLineWarning":false,"position":6,"left":1495,"right":1496},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1497,"text":"+\t * earlier call to WaitEventSetWait().","html":"+\u003cspan class=pl-c\u003e\t * earlier call to WaitEventSetWait().\u003c/span\u003e","displayNoNewLineWarning":false,"position":7,"left":1495,"right":1497},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1498,"text":"+\t */","html":"+\u003cspan class=pl-c\u003e\t */\u003c/span\u003e","displayNoNewLineWarning":false,"position":8,"left":1495,"right":1498},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1499,"text":" \tif (unlikely(set-\u003ereport_postmaster_not_running))","html":" \t\u003cspan class=pl-k\u003eif\u003c/span\u003e (\u003cspan class=pl-en\u003eunlikely\u003c/span\u003e(\u003cspan class=pl-s1\u003eset\u003c/span\u003e\u003cspan class=pl-c1\u003e-\u0026gt;\u003c/span\u003e\u003cspan class=pl-c1\u003ereport_postmaster_not_running\u003c/span\u003e))","displayNoNewLineWarning":false,"position":9,"left":1496,"right":1499},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1500,"text":" \t{","html":" \t{","displayNoNewLineWarning":false,"position":10,"left":1497,"right":1500},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1501,"text":" \t\tif (set-\u003eexit_on_postmaster_death)","html":" \t\t\u003cspan class=pl-k\u003eif\u003c/span\u003e (\u003cspan class=pl-s1\u003eset\u003c/span\u003e\u003cspan class=pl-c1\u003e-\u0026gt;\u003c/span\u003e\u003cspan class=pl-c1\u003eexit_on_postmaster_death\u003c/span\u003e)","displayNoNewLineWarning":false,"position":11,"left":1498,"right":1501},{"stylingDirective":null,"type":"HUNK","blobLineNumber":1565,"text":"@@ -1563,6 +1566,13 @@ WaitEventSetWaitBlock(WaitEventSet *set, int cur_timeout,","html":"@@ -1563,6 +1566,13 @@ WaitEventSetWaitBlock(WaitEventSet *set, int cur_timeout,","displayNoNewLineWarning":false,"position":12,"left":1562,"right":1565},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1566,"text":" \t\t\t\t cur_kqueue_event-\u003efilter == EVFILT_PROC \u0026\u0026","html":" \t\t\t\t \u003cspan class=pl-s1\u003ecur_kqueue_event\u003c/span\u003e\u003cspan class=pl-c1\u003e-\u0026gt;\u003c/span\u003e\u003cspan class=pl-c1\u003efilter\u003c/span\u003e \u003cspan class=pl-c1\u003e==\u003c/span\u003e \u003cspan class=pl-c1\u003eEVFILT_PROC\u003c/span\u003e \u003cspan class=pl-c1\u003e\u0026amp;\u0026amp;\u003c/span\u003e","displayNoNewLineWarning":false,"position":13,"left":1563,"right":1566},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1567,"text":" \t\t\t\t (cur_kqueue_event-\u003efflags \u0026 NOTE_EXIT) != 0)","html":" \t\t\t\t (\u003cspan class=pl-s1\u003ecur_kqueue_event\u003c/span\u003e\u003cspan class=pl-c1\u003e-\u0026gt;\u003c/span\u003e\u003cspan class=pl-c1\u003efflags\u003c/span\u003e \u003cspan class=pl-c1\u003e\u0026amp;\u003c/span\u003e \u003cspan class=pl-c1\u003eNOTE_EXIT\u003c/span\u003e) \u003cspan class=pl-c1\u003e!=\u003c/span\u003e \u003cspan class=pl-c1\u003e0\u003c/span\u003e)","displayNoNewLineWarning":false,"position":14,"left":1564,"right":1567},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1568,"text":" \t\t{","html":" \t\t{","displayNoNewLineWarning":false,"position":15,"left":1565,"right":1568},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1569,"text":"+\t\t\t/*","html":"+\t\t\t\u003cspan class=pl-c\u003e/*\u003c/span\u003e","displayNoNewLineWarning":false,"position":16,"left":1565,"right":1569},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1570,"text":"+\t\t\t * The kernel will tell this kqueue object only once about the exit","html":"+\u003cspan class=pl-c\u003e\t\t\t * The kernel will tell this kqueue object only once about the exit\u003c/span\u003e","displayNoNewLineWarning":false,"position":17,"left":1565,"right":1570},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1571,"text":"+\t\t\t * of the postmaster, so let's remember that for next time so that","html":"+\u003cspan class=pl-c\u003e\t\t\t * of the postmaster, so let\u0026#39;s remember that for next time so that\u003c/span\u003e","displayNoNewLineWarning":false,"position":18,"left":1565,"right":1571},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1572,"text":"+\t\t\t * we provide level-triggered semantics.","html":"+\u003cspan class=pl-c\u003e\t\t\t * we provide level-triggered semantics.\u003c/span\u003e","displayNoNewLineWarning":false,"position":19,"left":1565,"right":1572},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1573,"text":"+\t\t\t */","html":"+\u003cspan class=pl-c\u003e\t\t\t */\u003c/span\u003e","displayNoNewLineWarning":false,"position":20,"left":1565,"right":1573},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1574,"text":"+\t\t\tset-\u003ereport_postmaster_not_running = true;","html":"+\t\t\t\u003cspan class=pl-s1\u003eset\u003c/span\u003e\u003cspan class=pl-c1\u003e-\u0026gt;\u003c/span\u003e\u003cspan class=pl-c1\u003ereport_postmaster_not_running\u003c/span\u003e \u003cspan class=pl-c1\u003e=\u003c/span\u003e true;","displayNoNewLineWarning":false,"position":21,"left":1565,"right":1574},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1575,"text":"+","html":"+","displayNoNewLineWarning":false,"position":22,"left":1565,"right":1575},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1576,"text":" \t\t\tif (set-\u003eexit_on_postmaster_death)","html":" \t\t\t\u003cspan class=pl-k\u003eif\u003c/span\u003e (\u003cspan class=pl-s1\u003eset\u003c/span\u003e\u003cspan class=pl-c1\u003e-\u0026gt;\u003c/span\u003e\u003cspan class=pl-c1\u003eexit_on_postmaster_death\u003c/span\u003e)","displayNoNewLineWarning":false,"position":23,"left":1566,"right":1576},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1577,"text":" \t\t\t\tproc_exit(1);","html":" \t\t\t\t\u003cspan class=pl-en\u003eproc_exit\u003c/span\u003e(\u003cspan class=pl-c1\u003e1\u003c/span\u003e);","displayNoNewLineWarning":false,"position":24,"left":1567,"right":1577},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1578,"text":" \t\t\toccurred_events-\u003efd = PGINVALID_SOCKET;","html":" \t\t\t\u003cspan class=pl-s1\u003eoccurred_events\u003c/span\u003e\u003cspan class=pl-c1\u003e-\u0026gt;\u003c/span\u003e\u003cspan class=pl-c1\u003efd\u003c/span\u003e \u003cspan class=pl-c1\u003e=\u003c/span\u003e \u003cspan class=pl-c1\u003ePGINVALID_SOCKET\u003c/span\u003e;","displayNoNewLineWarning":false,"position":25,"left":1568,"right":1578}],"diffNumber":0,"diffSize":"0 Bytes","isBinary":false,"isTooBig":false,"collapsed":false,"isSubmodule":false,"lineCount":2025,"linesChanged":12,"newTreeEntry":{"lineCount":2025,"path":"src/backend/storage/ipc/latch.c","mode":100644,"isGenerated":false},"oldTreeEntry":{"lineCount":0,"path":"src/backend/storage/ipc/latch.c","mode":100644},"linesAdded":11,"linesDeleted":1,"path":"src/backend/storage/ipc/latch.c","pathDigest":"6e542ba2eb1d83ef90e65cdc0912b51a295184701c7e3bd236937c43c4cac4b9","status":"MODIFIED","truncatedReason":null,"oldOid":"a04daa97a4339c38e304cd6164d37da540d665a8","newOid":"b94109ce375b137f235149bfba3559c69f4573e7","copilotChatReference":null,"deletedSha":"a04daa97a4339c38e304cd6164d37da540d665a8","canToggleRichDiff":false,"defaultToRichDiff":false,"proseDifffHtml":null,"renderInfo":null,"dependencyDiffPath":null,"submodule":null}],"splitViewPreference":"unified","ignoreWhitespace":false,"repoOwnerGlobalRelayId":"MDEyOk9yZ2FuaXphdGlvbjE3NzU0Mw==","commentsPreference":"visible","diffLineSpacingPreference":"relaxed","useMonospaceFont":false,"pasteUrlLinkAsPlainText":false,"userNotices":[],"path":"/postgres/postgres/commit/b94109ce375b137f235149bfba3559c69f4573e7","fileTreeExpanded":true,"headerInfo":{"additions":11,"deletions":1,"filesChanged":1,"filesChangedString":"1"},"moreDiffsToLoad":false,"asyncDiffLoadInfo":{"startIndex":1,"truncated":false,"byteCount":932,"lineShownCount":26},"commentInfo":{"canComment":false,"locked":false,"canLock":false,"repoArchived":false},"csrf_tokens":{"/users/diffview?diff=split":{"post":"NIc1mIRC5R0IVt9rc1TSWsKtYuDFtH4Hy-trRfjxtEi-LuBvdMQKfwxHde3IIHADwfzm5l4CPffUQKSd5DRpog"},"/users/diffview?diff=unified":{"post":"9J3UrqUiwQrDTT8RAXehNXr4tapMU-nQItN3l8OGND9-NAFZVaQuaMdclZe6AwNseakxrNflqiA9eLhP30Pp1Q"},"/notifications/thread":{"post":"v_buJuqlpuRud6vOjwPZUM8psgENB6zsRk5etMYYKQWATptHiDDVbtd-2srUtvRFvCotWGhEtaAB4JfNIrja7w"}}},"title":"Make WL_POSTMASTER_DEATH level-triggered on kqueue builds. · postgres/postgres@b94109c","appPayload":{"helpUrl":"https://docs.github.com","findInDiffWorkerPath":"/assets-cdn/worker/find-in-diff-worker-2bfe39677d14.js","enabled_features":{"diff_ux_refresh_beta":false,"diff_inline_comments":true,"diff_ux_refresh_ssr_five":false,"diff_ux_refresh_ssr_ten":false,"react_diff_line_type_character_correction":true}}}

Commit b94109c

Browse files
committed
Make WL_POSTMASTER_DEATH level-triggered on kqueue builds.
If WaitEventSetWait() reports that the postmaster has gone away, later calls to WaitEventSetWait() should continue to report that. Otherwise further waits that occur in the proc_exit() path after we already noticed the postmaster's demise could block forever. Back-patch to 13, where the kqueue support landed. Reported-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/3624029.1602701929%40sss.pgh.pa.us
1 parent a04daa9 commit b94109c

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/backend/storage/ipc/latch.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1492,7 +1492,10 @@ WaitEventSetWaitBlock(WaitEventSet *set, int cur_timeout,
14921492
timeout_p = &timeout;
14931493
}
14941494

1495-
/* Report events discovered by WaitEventAdjustKqueue(). */
1495+
/*
1496+
* Report postmaster events discovered by WaitEventAdjustKqueue() or an
1497+
* earlier call to WaitEventSetWait().
1498+
*/
14961499
if (unlikely(set->report_postmaster_not_running))
14971500
{
14981501
if (set->exit_on_postmaster_death)
@@ -1563,6 +1566,13 @@ WaitEventSetWaitBlock(WaitEventSet *set, int cur_timeout,
15631566
cur_kqueue_event->filter == EVFILT_PROC &&
15641567
(cur_kqueue_event->fflags & NOTE_EXIT) != 0)
15651568
{
1569+
/*
1570+
* The kernel will tell this kqueue object only once about the exit
1571+
* of the postmaster, so let's remember that for next time so that
1572+
* we provide level-triggered semantics.
1573+
*/
1574+
set->report_postmaster_not_running = true;
1575+
15661576
if (set->exit_on_postmaster_death)
15671577
proc_exit(1);
15681578
occurred_events->fd = PGINVALID_SOCKET;

0 commit comments

Comments
 (0)
0