Skip to content

Commit 78ce2dc

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 ba7bee8 commit 78ce2dc

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
@@ -1358,15 +1358,27 @@ pgwin32_ServiceMain(DWORD argc, LPTSTR *argv)
13581358
switch (ret)
13591359
{
13601360
case WAIT_OBJECT_0: /* shutdown event */
1361-
kill(postmasterPID, SIGINT);
1361+
{
1362+
/*
1363+
* status.dwCheckPoint can be incremented by
1364+
* test_postmaster_connection(true), so it might not
1365+
* start from 0.
1366+
*/
1367+
int maxShutdownCheckPoint = status.dwCheckPoint + 12;;
13621368

1363-
/*
1364-
* Increment the checkpoint and try again Abort after 12
1365-
* checkpoints as the postmaster has probably hung
1366-
*/
1367-
while (WaitForSingleObject(postmasterProcess, 5000) == WAIT_TIMEOUT && status.dwCheckPoint < 12)
1368-
status.dwCheckPoint++;
1369-
break;
1369+
kill(postmasterPID, SIGINT);
1370+
1371+
/*
1372+
* Increment the checkpoint and try again. Abort after 12
1373+
* checkpoints as the postmaster has probably hung.
1374+
*/
1375+
while (WaitForSingleObject(postmasterProcess, 5000) == WAIT_TIMEOUT && status.dwCheckPoint < maxShutdownCheckPoint)
1376+
{
1377+
status.dwCheckPoint++;
1378+
SetServiceStatus(hStatus, (LPSERVICE_STATUS) &status);
1379+
}
1380+
break;
1381+
}
13701382

13711383
case (WAIT_OBJECT_0 + 1): /* postmaster went down */
13721384
break;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy