Skip to content

Commit 382009e

Browse files
authored
Relax the checks/assertions on which PID owns the semaphore (#822)
It turns out that the checks to ensure which PID owns the semaphore is too aggressive. The PID might be 0, pid of our own process or any process above to our PID in the process tree. So, we simplify the rule. We only terminate the semaphore when we are owner of the PID. Else, we wait until the owner of the PID exits (which will eventually happen).
1 parent 8e652ce commit 382009e

1 file changed

Lines changed: 3 additions & 16 deletions

File tree

src/bin/pg_autoctl/lock_utils.c

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -107,27 +107,14 @@ semaphore_finish(Semaphore *semaphore)
107107
* its semId as found in our environment variable PG_AUTOCTL_LOG_SEMAPHORE.
108108
*
109109
* At finish time (called from the atexit(3) registry), we remove the
110-
* semaphore only when we are the owner of it. We expect semaphore->owner
111-
* to be either zero (0), or to have been filled with our own pid.
110+
* semaphore only when we are the owner of it.
112111
*/
113-
if (semaphore->owner == 0)
114-
{
115-
/* there's no semaphore closing protocol in SysV */
116-
return true;
117-
}
118-
else if (semaphore->owner == getpid())
112+
if (semaphore->owner == getpid())
119113
{
120114
return semaphore_unlink(semaphore);
121115
}
122-
else
123-
{
124-
log_fatal("BUG: semaphore_finish semId %d owner is %d, getpid is %d",
125-
semaphore->semId,
126-
semaphore->owner,
127-
getpid());
128116

129-
return false;
130-
}
117+
return true;
131118
}
132119

133120

0 commit comments

Comments
 (0)