Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Xj0o9-0004Tw-79 for pgsql-bugs@arkaria.postgresql.org; Tue, 28 Oct 2014 07:03:09 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Xj0o8-0007Tu-89 for pgsql-bugs@arkaria.postgresql.org; Tue, 28 Oct 2014 07:03:08 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Xj0o7-0007Tn-9a for pgsql-bugs@postgresql.org; Tue, 28 Oct 2014 07:03:07 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Xj0o3-00054T-HI for pgsql-bugs@postgresql.org; Tue, 28 Oct 2014 07:03:06 +0000 MIME-Version: 1.0 Subject: BUG #11805: Missing SetServiceStatus call during service shutdown in pg_ctl (Windows only) To: pgsql-bugs@postgresql.org From: krystian.bigaj@gmail.com Date: Tue, 28 Oct 2014 07:02:41 +0000 Message-ID: <20141028070241.2593.58180@wrigleys.postgresql.org> X-Pg-Spam-Score: -0.3 (/) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org 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.com 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