Skip to content

Commit 1bdae16

Browse files
committed
walreceiver: tweak pg_stat_wal_receiver behavior
There are two problems in the original coding: one is that if one walreceiver process exits, the ready_to_display flag remains set in shared memory, exposing the conninfo of the next walreceiver before obfuscating. Fix by having WalRcvDie reset the flag. Second, the sleep-and-retry behavior that waited until walreceiver had set ready_to_display wasn't liked; the preference is to have it return no data instead, so let's do that. Bugs in 9ed551e reported by Fujii Masao and Michël Paquier. Author: Michaël Paquier
1 parent 9e70398 commit 1bdae16

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

src/backend/replication/walreceiver.c

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ WalReceiverMain(void)
246246
walrcv->walRcvState = WALRCV_STREAMING;
247247

248248
/* Fetch information required to start streaming */
249+
walrcv->ready_to_display = false;
249250
strlcpy(conninfo, (char *) walrcv->conninfo, MAXCONNINFO);
250251
strlcpy(slotname, (char *) walrcv->slotname, NAMEDATALEN);
251252
startpoint = walrcv->receiveStart;
@@ -770,6 +771,7 @@ WalRcvDie(int code, Datum arg)
770771
Assert(walrcv->pid == MyProcPid);
771772
walrcv->walRcvState = WALRCV_STOPPED;
772773
walrcv->pid = 0;
774+
walrcv->ready_to_display = false;
773775
SpinLockRelease(&walrcv->mutex);
774776

775777
/* Terminate the connection gracefully. */
@@ -1343,24 +1345,12 @@ pg_stat_get_wal_receiver(PG_FUNCTION_ARGS)
13431345
char *slotname;
13441346
char *conninfo;
13451347

1346-
/* No WAL receiver, just return a tuple with NULL values */
1347-
if (walrcv->pid == 0)
1348-
PG_RETURN_NULL();
1349-
13501348
/*
1351-
* Users attempting to read this data mustn't be shown security sensitive
1352-
* data, so sleep until everything has been properly obfuscated.
1349+
* No WAL receiver (or not ready yet), just return a tuple with NULL
1350+
* values
13531351
*/
1354-
retry:
1355-
SpinLockAcquire(&walrcv->mutex);
1356-
if (!walrcv->ready_to_display)
1357-
{
1358-
SpinLockRelease(&walrcv->mutex);
1359-
CHECK_FOR_INTERRUPTS();
1360-
pg_usleep(1000);
1361-
goto retry;
1362-
}
1363-
SpinLockRelease(&walrcv->mutex);
1352+
if (walrcv->pid == 0 || !walrcv->ready_to_display)
1353+
PG_RETURN_NULL();
13641354

13651355
/* determine result type */
13661356
if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy