Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 43ed068

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 6d78a17 commit 43ed068

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
@@ -1590,15 +1590,27 @@ pgwin32_ServiceMain(DWORD argc, LPTSTR *argv)
15901590
switch (ret)
15911591
{
15921592
case WAIT_OBJECT_0: /* shutdown event */
1593-
kill(postmasterPID, SIGINT);
1593+
{
1594+
/*
1595+
* status.dwCheckPoint can be incremented by
1596+
* test_postmaster_connection(true), so it might not
1597+
* start from 0.
1598+
*/
1599+
int maxShutdownCheckPoint = status.dwCheckPoint + 12;;
15941600

1595-
/*
1596-
* Increment the checkpoint and try again Abort after 12
1597-
* checkpoints as the postmaster has probably hung
1598-
*/
1599-
while (WaitForSingleObject(postmasterProcess, 5000) == WAIT_TIMEOUT && status.dwCheckPoint < 12)
1600-
status.dwCheckPoint++;
1601-
break;
1601+
kill(postmasterPID, SIGINT);
1602+
1603+
/*
1604+
* Increment the checkpoint and try again. Abort after 12
1605+
* checkpoints as the postmaster has probably hung.
1606+
*/
1607+
while (WaitForSingleObject(postmasterProcess, 5000) == WAIT_TIMEOUT && status.dwCheckPoint < maxShutdownCheckPoint)
1608+
{
1609+
status.dwCheckPoint++;
1610+
SetServiceStatus(hStatus, (LPSERVICE_STATUS) &status);
1611+
}
1612+
break;
1613+
}
16021614

16031615
case (WAIT_OBJECT_0 + 1): /* postmaster went down */
16041616
break;

0 commit comments

Comments
 (0)