Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9eacd42

Browse files
committed
Make sure walsender state is only read while holding the spinlock
Noted by Robert Haas.
1 parent 712dd95 commit 9eacd42

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/backend/replication/walsender.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,7 @@ pg_stat_get_wal_senders(PG_FUNCTION_ARGS)
10501050
volatile WalSnd *walsnd = &WalSndCtl->walsnds[i];
10511051
char sent_location[MAXFNAMELEN];
10521052
XLogRecPtr sentPtr;
1053+
WalSndState state;
10531054
Datum values[PG_STAT_GET_WAL_SENDERS_COLS];
10541055
bool nulls[PG_STAT_GET_WAL_SENDERS_COLS];
10551056

@@ -1058,14 +1059,15 @@ pg_stat_get_wal_senders(PG_FUNCTION_ARGS)
10581059

10591060
SpinLockAcquire(&walsnd->mutex);
10601061
sentPtr = walsnd->sentPtr;
1062+
state = walsnd->state;
10611063
SpinLockRelease(&walsnd->mutex);
10621064

10631065
snprintf(sent_location, sizeof(sent_location), "%X/%X",
10641066
sentPtr.xlogid, sentPtr.xrecoff);
10651067

10661068
memset(nulls, 0, sizeof(nulls));
10671069
values[0] = Int32GetDatum(walsnd->pid);
1068-
values[1] = CStringGetTextDatum(WalSndGetStateString(walsnd->state));
1070+
values[1] = CStringGetTextDatum(WalSndGetStateString(state));
10691071
values[2] = CStringGetTextDatum(sent_location);
10701072

10711073
tuplestore_putvalues(tupstore, tupdesc, values, nulls);

0 commit comments

Comments
 (0)