Fix race condition in startup progress reporting.

Commit 9ce346eabf added startup
progress reporting, but begin_startup_progress_phase has a race
condition: the timeout for the previous phase might fire just
before we reschedule the interrupt for the next phase.

To avoid the race, disable the timeout, clear the flag, and then
re-enable the timeout.

Patch by me, reviewed by Nitin Jadhav.

Discussion: https://postgr.es/m/CA+TgmoYq38i6iAzfRLVxA6Cm+wMCf4WM8wC3o_a+X_JvWC8bJg@mail.gmail.com
This commit is contained in:
Robert Haas 2021-10-29 14:40:15 -04:00
parent 2f5c4397c3
commit 5ccceb2946
1 changed files with 2 additions and 0 deletions

View File

@ -320,6 +320,8 @@ begin_startup_progress_phase(void)
if (log_startup_progress_interval == 0)
return;
disable_timeout(STARTUP_PROGRESS_TIMEOUT, false);
startup_progress_timer_expired = false;
startup_progress_phase_start_time = GetCurrentTimestamp();
fin_time = TimestampTzPlusMilliseconds(startup_progress_phase_start_time,
log_startup_progress_interval);