I found an older thread about the same bug[0]. Sorry I missed it before. Justin Pryzby reported it in December 2023. Thomas Munro reproduced it and identified the same window: FatalError is still set, the postmaster has not yet processed PMSIGNAL_RECOVERY_STARTED, and shutdown gets stuck waiting for the checkpointer. Thomas proposed a fix in that thread, and Noah Misch later reproduced the problem and suggested clearing FatalError when the replacement startup process is launched instead [1]. There is also an old CommitFest entry for Thomas's patch [2].
The deterministic test in patch 0002 covers that report as well. Patch 0003 takes a third approach that only became directly available recently. HandleFatalError() did not exist when Thomas posted his patch; after it was introduced, it asserted that FatalError was not already set. ead8f696b7cd removed that restriction. This lets 0003 retain FatalError during crash restart and handle a shutdown request in that interval through HandleFatalError(PMQUIT_FOR_STOP, false). The version from [2] perhaps is easier to backpatch to 15-17 if we want to backpatch. Best regards, Andrey Borodin. [0] https://www.postgresql.org/message-id/flat/ZWlrdQarrZvLsgIk%40pryzbyj2023 [1] https://www.postgresql.org/message-id/20241025181701.ed.nmisch%40google.com [2] https://commitfest.postgresql.org/patch/4884/
