pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: krystian.bigaj@gmail.com
To: pgsql-bugs@postgresql.org
Subject: BUG #11805: Missing SetServiceStatus call during service shutdown in pg_ctl (Windows only)
Date: Tue, 28 Oct 2014 07:02:41 +0000
Message-ID: <20141028070241.2593.58180@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

The following bug has been logged on the website:

Bug reference:      11805
Logged by:          Krystian Bigaj
Email address:      krystian.bigaj@gmail.com
PostgreSQL version: 9.3.5
Operating system:   Windows 7 Pro x64
Description:        

pg_ctl on Windows during service start/shutdown should notify service
manager about it's status by increment dwCheckPoint and call to
SetServiceStatus/pgwin32_SetServiceStatus.

However during shutdown there is a missing call to SetServiceStatus.
See src\bin\pg_ctl\pg_ctl.c:
[code]
static void WINAPI
pgwin32_ServiceMain(DWORD argc, LPTSTR *argv)
{
...
            /*
             * Increment the checkpoint and try again Abort after 12
             * checkpoints as the postmaster has probably hung
             */
            while (WaitForSingleObject(postmasterProcess, 5000) ==
WAIT_TIMEOUT && status.dwCheckPoint < 12)
                status.dwCheckPoint++;  <------- missing SetServiceStatus
call
            break;

        case (WAIT_OBJECT_0 + 1):       /* postmaster went down */
            break;
[/code]

As you can see there is only a dwCheckPoint increment, but there is no call
to SetServiceStatus(hStatus, (LPSERVICE_STATUS) &status);
This problem was reported before here:
http://www.postgresql.org/message-id/CAN=kAeGOEmfh_+vdg+2oD=9KhWzGn4NNqfZNdHoQ_2QOsHhuLQ@mail.gmail....

Another problem is with above condition "status.dwCheckPoint < 12" if
service (pg_ctl) is started with -w parameter (wait for startup).
In that case test_postmaster_connection(true) increments
status.dwCheckPoint,
so during shutdown that value can be larger than 0 (and even larger than 12,
because default wait time is 60s), so there could be only one 5000ms wait
for postmaster shutdown.

Patch to fix for this bugs could looks like this:
[code]
        case WAIT_OBJECT_0:     /* shutdown event */
            /*
             * Value status.dwCheckPoint can be incremented by
test_postmaster_connection(true)
             * so dwCheckPoint might not start from 0.
             */
            int maxShutdownCheckPoint = status.dwCheckPoint + 12;

            kill(postmasterPID, SIGINT);

            /*
             * Increment the checkpoint and try again Abort after 12
             * checkpoints as the postmaster has probably hung
             */
            while (WaitForSingleObject(postmasterProcess, 5000) ==
WAIT_TIMEOUT && status.dwCheckPoint < maxShutdownCheckPoint)
            {
                status.dwCheckPoint++;
                SetServiceStatus(hStatus, (LPSERVICE_STATUS) &status);
            }
            break;
[/code]



-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (7+ messages)  latest in thread

Message-ID: <20141028070241.2593.58180@wrigleys.postgresql.org>
Permalink:  ../20141028070241.2593.58180@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/20141028070241.2593.58180@wrigleys.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: krystian.bigaj@gmail.com
  Subject: Re: BUG #11805: Missing SetServiceStatus call during service shutdown in pg_ctl (Windows only)
  In-Reply-To: <20141028070241.2593.58180@wrigleys.postgresql.org>
  References: <20141028070241.2593.58180@wrigleys.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox