Skip to content

Commit 1a241d2

Browse files
committed
Properly send SCM status updates when shutting down service on Windows
The Service Control Manager should be notified regularly during a shutdown that takes a long time. Previously we would increaes the counter, but forgot to actually send the notification to the system. The loop counter was also incorrectly initalized in the event that the startup of the system took long enough for it to increase, which could cause the shutdown process not to wait as long as expected. Krystian Bigaj, reviewed by Michael Paquier
1 parent d678bde commit 1a241d2

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/bin/pg_ctl/pg_ctl.c

+20-8
Original file line numberDiff line numberDiff line change
@@ -1597,15 +1597,27 @@ pgwin32_ServiceMain(DWORD argc, LPTSTR *argv)
15971597
switch (ret)
15981598
{
15991599
case WAIT_OBJECT_0: /* shutdown event */
1600-
kill(postmasterPID, SIGINT);
1600+
{
1601+
/*
1602+
* status.dwCheckPoint can be incremented by
1603+
* test_postmaster_connection(true), so it might not
1604+
* start from 0.
1605+
*/
1606+
int maxShutdownCheckPoint = status.dwCheckPoint + 12;;
16011607

1602-
/*
1603-
* Increment the checkpoint and try again Abort after 12
1604-
* checkpoints as the postmaster has probably hung
1605-
*/
1606-
while (WaitForSingleObject(postmasterProcess, 5000) == WAIT_TIMEOUT && status.dwCheckPoint < 12)
1607-
status.dwCheckPoint++;
1608-
break;
1608+
kill(postmasterPID, SIGINT);
1609+
1610+
/*
1611+
* Increment the checkpoint and try again. Abort after 12
1612+
* checkpoints as the postmaster has probably hung.
1613+
*/
1614+
while (WaitForSingleObject(postmasterProcess, 5000) == WAIT_TIMEOUT && status.dwCheckPoint < maxShutdownCheckPoint)
1615+
{
1616+
status.dwCheckPoint++;
1617+
SetServiceStatus(hStatus, (LPSERVICE_STATUS) &status);
1618+
}
1619+
break;
1620+
}
16091621

16101622
case (WAIT_OBJECT_0 + 1): /* postmaster went down */
16111623
break;

0 commit comments

Comments
 (0)