sleep-to-expose-shmat-race-condition.patch
text/x-diff
Filename: sleep-to-expose-shmat-race-condition.patch
Type: text/x-diff
Part: 0
Patch
Format: unified
| File | + | − |
|---|---|---|
| src/backend/port/sysv_shmem.c | 5 | 2 |
diff --git a/src/backend/port/sysv_shmem.c b/src/backend/port/sysv_shmem.c
index a9d7bf9..d390ba4 100644
--- a/src/backend/port/sysv_shmem.c
+++ b/src/backend/port/sysv_shmem.c
@@ -387,6 +387,8 @@ PGSharedMemoryAttach(IpcMemoryId shmId,
if (stat(DataDir, &statbuf) < 0)
return SHMSTATE_ANALYSIS_FAILURE; /* can't stat; be conservative */
+ pg_usleep(100000);
+
/*
* Attachment fails if we have no write permission. Since that will never
* happen with Postgres IPCProtection, such a failure shows the segment is
@@ -398,8 +400,9 @@ PGSharedMemoryAttach(IpcMemoryId shmId,
{
if (errno == EACCES)
return SHMSTATE_FOREIGN;
- else
- return SHMSTATE_ANALYSIS_FAILURE;
+ elog(LOG, "shmat(0x%lx) failed: %m, nattch had been %ld",
+ (long) shmId, (long) shmStat.shm_nattch);
+ return SHMSTATE_ANALYSIS_FAILURE;
}
*addr = hdr;