Commit 1bdae16f authored by Alvaro Herrera's avatar Alvaro Herrera

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 9ed551e0 reported by Fujii Masao and Michël Paquier.

Author: Michaël Paquier
parent 9e703987
...@@ -246,6 +246,7 @@ WalReceiverMain(void) ...@@ -246,6 +246,7 @@ WalReceiverMain(void)
walrcv->walRcvState = WALRCV_STREAMING; walrcv->walRcvState = WALRCV_STREAMING;
/* Fetch information required to start streaming */ /* Fetch information required to start streaming */
walrcv->ready_to_display = false;
strlcpy(conninfo, (char *) walrcv->conninfo, MAXCONNINFO); strlcpy(conninfo, (char *) walrcv->conninfo, MAXCONNINFO);
strlcpy(slotname, (char *) walrcv->slotname, NAMEDATALEN); strlcpy(slotname, (char *) walrcv->slotname, NAMEDATALEN);
startpoint = walrcv->receiveStart; startpoint = walrcv->receiveStart;
...@@ -770,6 +771,7 @@ WalRcvDie(int code, Datum arg) ...@@ -770,6 +771,7 @@ WalRcvDie(int code, Datum arg)
Assert(walrcv->pid == MyProcPid); Assert(walrcv->pid == MyProcPid);
walrcv->walRcvState = WALRCV_STOPPED; walrcv->walRcvState = WALRCV_STOPPED;
walrcv->pid = 0; walrcv->pid = 0;
walrcv->ready_to_display = false;
SpinLockRelease(&walrcv->mutex); SpinLockRelease(&walrcv->mutex);
/* Terminate the connection gracefully. */ /* Terminate the connection gracefully. */
...@@ -1343,24 +1345,12 @@ pg_stat_get_wal_receiver(PG_FUNCTION_ARGS) ...@@ -1343,24 +1345,12 @@ pg_stat_get_wal_receiver(PG_FUNCTION_ARGS)
char *slotname; char *slotname;
char *conninfo; char *conninfo;
/* No WAL receiver, just return a tuple with NULL values */
if (walrcv->pid == 0)
PG_RETURN_NULL();
/* /*
* Users attempting to read this data mustn't be shown security sensitive * No WAL receiver (or not ready yet), just return a tuple with NULL
* data, so sleep until everything has been properly obfuscated. * values
*/ */
retry: if (walrcv->pid == 0 || !walrcv->ready_to_display)
SpinLockAcquire(&walrcv->mutex); PG_RETURN_NULL();
if (!walrcv->ready_to_display)
{
SpinLockRelease(&walrcv->mutex);
CHECK_FOR_INTERRUPTS();
pg_usleep(1000);
goto retry;
}
SpinLockRelease(&walrcv->mutex);
/* determine result type */ /* determine result type */
if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment