8000 Properly send SCM status updates when shutting down service on Windows · lansz/postgres@447e165 · GitHub
[go: up one dir, main page]

Skip to content

Commit 447e165

Browse files
committed
Properly send SCM status updates when shutting down service on Windows 8000
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 bf85ba2 commit 447e165

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/bin/pg_ctl/pg_ctl.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,15 +1510,27 @@ pgwin32_ServiceMain(DWORD argc, LPTSTR *argv)
15101510
switch (ret)
15111511
{
15121512
case WAIT_OBJECT_0: /* shutdown event */
1513-
kill(postmasterPID, SIGINT);
1513+
{
1514+
/*
1515+
* status.dwCheckPoint can be incremented by
1516+
* test_postmaster_connection(true), so it might not
1517+
* start from 0.
1518+
*/
1519+
int maxShutdownCheckPoint = status.dwCheckPoint + 12;;
15141520

1515-
/*
1516-
* Increment the checkpoint and try again Abort after 12
1517-
* checkpoints as the postmaster has probably hung
1518-
*/
1519-
while (WaitForSingleObject(postmasterProcess, 5000) == WAIT_TIMEOUT && status.dwCheckPoint < 12)
1520-
status.dwCheckPoint++;
1521-
break;
1521+
kill(postmasterPID, SIGINT);
1522+
1523+
/*
1524+
* Increment the checkpoint and try again. Abort after 12
1525+
* checkpoints as the postmaster has probably hung.
1526+
*/
1527+
while (WaitForSingleObject(postmasterProcess, 5000) == WAIT_TIMEOUT && status.dwCheckPoint < maxShutdownCheckPoint)
1528+
{
1529+
status.dwCheckPoint++;
1530+
SetServiceStatus(hStatus, (LPSERVICE_STATUS) &status);
1531+
}
1532+
break;
1533+
}
15221534

15231535
case (WAIT_OBJECT_0 + 1): /* postmaster went down */
15241536
break;

0 commit comments

Comments
 (0)
0