Add debugging help in OwnLatch().
authorThomas Munro <tmunro@postgresql.org>
Mon, 30 May 2022 23:38:19 +0000 (11:38 +1200)
committerThomas Munro <tmunro@postgresql.org>
Tue, 31 May 2022 00:06:11 +0000 (12:06 +1200)
Build farm animal gharial recently failed a few times in a parallel
worker's call to OwnLatch() with "ERROR:  latch already owned".  Let's
turn that into a PANIC and show the PID of the owner, to try to learn
more.

Discussion: https://postgr.es/m/CA%2BhUKGJ_0RGcr7oUNzcHdn7zHqHSB_wLSd3JyS2YC_DYB%2B-V%3Dg%40mail.gmail.com

src/backend/storage/ipc/latch.c

index 78c6a89271316eeae56c8cabf407e0b24ac50dda..41d359d68ed7f931d3d36f778644f6518ca68635 100644 (file)
@@ -402,6 +402,8 @@ InitSharedLatch(Latch *latch)
 void
 OwnLatch(Latch *latch)
 {
+   int         owner_pid;
+
    /* Sanity checks */
    Assert(latch->is_shared);
 
@@ -410,8 +412,9 @@ OwnLatch(Latch *latch)
    Assert(selfpipe_readfd >= 0 && selfpipe_owner_pid == MyProcPid);
 #endif
 
-   if (latch->owner_pid != 0)
-       elog(ERROR, "latch already owned");
+   owner_pid = latch->owner_pid;
+   if (owner_pid != 0)
+       elog(PANIC, "latch already owned by PID %d", owner_pid);
 
    latch->owner_pid = MyProcPid;
 }