Skip to content

Commit 6b2daef

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 45ec8da commit 6b2daef

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
@@ -196,6 +196,7 @@ WalReceiverMain(void)
196196
/* use volatile pointer to prevent code rearrangement */
197197
volatile WalRcvData *walrcv = WalRcv;
198198
TimestampTz last_recv_timestamp;
199+
TimestampTz now;
199200
bool ping_sent;
200201

201202
/*
@@ -204,6 +205,8 @@ WalReceiverMain(void)
204205
*/
205206
Assert(walrcv != NULL);
206207

208+
now = GetCurrentTimestamp();
209+
207210
/*
208211
* Mark walreceiver as running in shared memory.
209212
*
@@ -234,6 +237,7 @@ WalReceiverMain(void)
234237
case WALRCV_RESTARTING:
235238
default:
236239
/* Shouldn't happen */
240+
SpinLockRelease(&walrcv->mutex);
237241
elog(PANIC, "walreceiver still running according to shared memory state");
238242
}
239243
/* Advertise our PID so that the startup process can kill us */
@@ -247,7 +251,8 @@ WalReceiverMain(void)
247251
startpointTLI = walrcv->receiveStartTLI;
248252

249253
/* Initialise to a sanish value */
250-
walrcv->lastMsgSendTime = walrcv->lastMsgReceiptTime = walrcv->latestWalEndTime = GetCurrentTimestamp();
254+
walrcv->lastMsgSendTime =
255+
walrcv->lastMsgReceiptTime = walrcv->latestWalEndTime = now;
251256

252257
SpinLockRelease(&walrcv->mutex);
253258

0 commit comments

Comments
 (0)