Skip to content

Commit c9c37e3

Browse files
committed
Fix coding rules violations in walreceiver.c
1. Since commit b1a9bad we had pstrdup() inside a spinlock-protected critical section; reported by Andreas Seltenreich. Turn those into strlcpy() to stack-allocated variables instead. Backpatch to 9.6. 2. Since commit 9ed551e we had a pfree() uselessly inside a spinlock-protected critical section. Tom Lane noticed in code review. Move down. Backpatch to 9.6. 3. Since commit 6423390 we had GetCurrentTimestamp() (a kernel call) inside a spinlock-protected critical section. Tom Lane noticed in code review. Move it up. Backpatch to 9.2. 4. Since commit 1bb2558 we did elog(PANIC) while holding spinlock. Tom Lane noticed in code review. Release spinlock before dying. Backpatch to 9.2. Discussion: https://postgr.es/m/87h8vhtgj2.fsf@ansel.ydns.eu
1 parent 72d4fd0 commit c9c37e3

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/backend/replication/walreceiver.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,16 @@ WalReceiverMain(void)
175175

176176
/* use volatile pointer to prevent code rearrangement */
177177
volatile WalRcvData *walrcv = WalRcv;
178+
TimestampTz now;
178179

179180
/*
180181
* WalRcv should be set up already (if we are a backend, we inherit this
181182
* by fork() or EXEC_BACKEND mechanism from the postmaster).
182183
*/
183184
Assert(walrcv != NULL);
184185

186+
now = GetCurrentTimestamp();
187+
185188
/*
186189
* Mark walreceiver as running in shared memory.
187190
*
@@ -209,6 +212,7 @@ WalReceiverMain(void)
209212

210213
case WALRCV_RUNNING:
211214
/* Shouldn't happen */
215+
SpinLockRelease(&walrcv->mutex);
212216
elog(PANIC, "walreceiver still running according to shared memory state");
213217
}
214218
/* Advertise our PID so that the startup process can kill us */
@@ -220,7 +224,8 @@ WalReceiverMain(void)
220224
startpoint = walrcv->receiveStart;
221225

222226
/* Initialise to a sanish value */
223-
walrcv->lastMsgSendTime = walrcv->lastMsgReceiptTime = walrcv->latestWalEndTime = GetCurrentTimestamp();
227+
walrcv->lastMsgSendTime =
228+
walrcv->lastMsgReceiptTime = walrcv->latestWalEndTime = now;
224229

225230
SpinLockRelease(&walrcv->mutex);
226231

0 commit comments

Comments
 (0)