Fix WaitLatch(NULL) on Windows.
authorThomas Munro <tmunro@postgresql.org>
Wed, 25 Nov 2020 04:44:15 +0000 (17:44 +1300)
committerThomas Munro <tmunro@postgresql.org>
Wed, 25 Nov 2020 04:55:49 +0000 (17:55 +1300)
Further to commit 733fa9aa, on Windows when a latch is triggered but we
aren't currently waiting for it, we need to locate the latch's HANDLE
rather than calling ResetEvent(NULL).

Author: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Reported-by: Ranier Vilela <ranier.vf@gmail.com>
Discussion: https://postgr.es/m/CAEudQArTPi1YBc%2Bn1fo0Asy3QBFhVjp_QgyKG-8yksVn%2ByRTiw%40mail.gmail.com

src/backend/storage/ipc/latch.c

index 24d44c982dabc01e85fa8cbe8a305727b9099851..24afc47d5134b4c459213b9ac48a46445b5d58a9 100644 (file)
@@ -1835,7 +1835,11 @@ WaitEventSetWaitBlock(WaitEventSet *set, int cur_timeout,
 
    if (cur_event->events == WL_LATCH_SET)
    {
-       if (!ResetEvent(set->latch->event))
+       /*
+        * We cannot use set->latch->event to reset the fired event if we
+        * aren't waiting on this latch now.
+        */
+       if (!ResetEvent(set->handles[cur_event->pos + 1]))
            elog(ERROR, "ResetEvent failed: error code %lu", GetLastError());
 
        if (set->latch && set->latch->is_set)