8000 Fix coding rules violations in walreceiver.c · koderP/postgres@b24f15f · GitHub
[go: up one dir, main page]

Skip to content

Commit b24f15f

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 d149aa7 commit b24f15f

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
195195
/* use volatile pointer to prevent code rearrangement */
196196
volatile WalRcvData *walrcv = WalRcv;
197197
TimestampTz last_recv_timestamp;
198+
TimestampTz now;
198199
bool ping_sent;
199200

200201
/*
@@ -203,6 +204,8 @@ WalReceiverMain(void)
203204
*/
204205
Assert(walrcv != NULL);
205206

207+
now = GetCurrentTimestamp();
208+
206209
/*
207210
* Mark walreceiver as running in shared memory.
208211
*
@@ -233,6 +236,7 @@ WalReceiverMain(void)
233236
case WALRCV_RESTARTING:
234237
default:
235238
/* Shouldn't happen */
239+
SpinLockRelease(&walrcv->mutex);
236240
elog(PANIC, "walreceiver still running according to shared memory state");
237241
}
238242
/* Advertise our PID so that the startup process can kill us */
@@ -245,7 +249,8 @@ WalReceiverMain(void)
245249
startpointTLI = walrcv->receiveStartTLI;
246250

247251
/* Initialise to a sanish value */
248-
walrcv->lastMsgSendTime = walrcv->lastMsgReceiptTime = walrcv->latestWalEndTime = GetCurrentTimestamp();
252+
walrcv->lastMsgSendTime =
253+
walrcv->lastMsgReceiptTime = walrcv->latestWalEndTime = now;
249254

250255
SpinLockRelease(&walrcv->mutex);
251256

0 commit comments

Comments
 (0)
0