Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vjg2S-0008A8-Qp for pgsql-bugs@arkaria.postgresql.org; Fri, 22 Nov 2013 02:00:09 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Vjg2S-0006hm-9x for pgsql-bugs@arkaria.postgresql.org; Fri, 22 Nov 2013 02:00:08 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vjg2Q-0006eJ-DB for pgsql-bugs@postgresql.org; Fri, 22 Nov 2013 02:00:06 +0000 Received: from alln-iport-5.cisco.com ([173.37.142.92]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vjg2L-0000un-Hn for pgsql-bugs@postgresql.org; Fri, 22 Nov 2013 02:00:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cisco.com; i=@cisco.com; l=10343; q=dns/txt; s=iport; t=1385085601; x=1386295201; h=from:to:subject:date:message-id:mime-version; bh=cqzl8BKk++G8Bz6T7IG4ZMu7K0ZdqRwX1BXLXy0Aj7E=; b=YWN7Eb6fUOROyb0lVGBdZLjkJ61lKAdbWaphe6Piv/8CWA2odZ4ArE05 J4W3VOEh767aq/BMdlHKN7uuW1OIsFT6U+x0z2iyOQsuXTp7Aohhp+0Ze 42zbbh7DSPMAnnGQ0gmrwzI1xprVycFNSrBXHlViYna62t59HRPru/DT4 E=; X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ah0IACy6jlKtJXG9/2dsb2JhbABZgkNEOFOza4d+ToEkFm0HgiyBCwGBABcBDwSIFA2ga6ATF40MgQhphD0DmBKBMJBggyiCKg X-IronPort-AV: E=Sophos;i="4.93,749,1378857600"; d="scan'208,217";a="1395575" Received: from rcdn-core2-2.cisco.com ([173.37.113.189]) by alln-iport-5.cisco.com with ESMTP; 22 Nov 2013 01:59:59 +0000 Received: from xhc-aln-x12.cisco.com (xhc-aln-x12.cisco.com [173.36.12.86]) by rcdn-core2-2.cisco.com (8.14.5/8.14.5) with ESMTP id rAM1xwqh007685 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=FAIL) for ; Fri, 22 Nov 2013 01:59:58 GMT Received: from xmb-rcd-x02.cisco.com ([169.254.4.82]) by xhc-aln-x12.cisco.com ([173.36.12.86]) with mapi id 14.03.0123.003; Thu, 21 Nov 2013 19:59:58 -0600 From: "Shiv Shivaraju Gowda (shivshi)" To: "pgsql-bugs@postgresql.org" Subject: PostgreSQL 6.2.5 Visual Studio Build does not pass the regression tests. Thread-Topic: PostgreSQL 6.2.5 Visual Studio Build does not pass the regression tests. Thread-Index: AQHO5yaLpRX7Gu3EVk6QAyW9AG/anQ== Date: Fri, 22 Nov 2013 01:59:58 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.155.252.183] Content-Type: multipart/alternative; boundary="_000_CEB3FA9D6450shivshiciscocom_" MIME-Version: 1.0 X-Pg-Spam-Score: -8.5 (--------) 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 --_000_CEB3FA9D6450shivshiciscocom_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable There seems to be a has a dormant bug in PostgreSQL source code build usin= g VisualStudio(VS) which shows up with the newer OS( not sure if it is the= OS or some other thing in the environment ). MinGW build doesn't access th= is code path and thus doesn't hit this bug. SYMPTOM: The following symptom is encountered in PostgreSQL build using Visual Studi= o: PostgreSQL regression tests fail with server crashing repeatedly with t= his message in the log file: "PANIC: could not lock semaphore: error code = 0". The issue is encountered for VS 2005, VS 2008( 32bit and 64bit executab= les), VS 2010 and VS 2012 built executables. The issue was reproducible wi= th PostgreSQL 6.2.3 and 6.2.5. We didn't encounter this issue in MinGW buil= d or EnterpriseDB Packaged executables (which seems to have been built usin= g VisualStudio 2010). CAUSE: The PGSemaphoreLock function in postgresql-9.2.5\src\backend\port\win32_sem= a.c (https://github.com/postgres/postgres/blob/master/src/backend/port/win3= 2_sema.c) uses "Ex" version of "WaitForMultipleObjects" Windows function (h= ttp://msdn.microsoft.com/en-us/library/windows/desktop/ms687028%28v=3Dvs.85= %29.aspx) however doesn't handle the additional awake calls from the "bAler= table" state. Specifically, it doesn't handle the WAIT_IO_COMPLETION return= code when woken up by a User-mode Asynchronous Procedure Call(APC) or Asyn= c IO completion. The part I do NOT understand is why do the User-Mode APC or Async IO comple= tion triggers get fired only in the executables we built and not in the one= s built by EnterpriseDB and bits built by other users since no one has comp= lained about it. Irrespective if it is triggered or not, the code should ha= ve handled all the return codes of the WaitForMultipleObjectsEX API and tha= t is the reason I think it is a bug. I checked the source code for calls which will trigger the Async IO or user= -mode APC(ReadFileEx, WriteFileEx, QueueUserAPC) and c= ould not find any. I am not sure what triggers the WAIT_IO_COMPLETION retur= n call. I could not find a way to figure out that information in the debug = environment. (Posible) FIX: Either of the following changes to the PGSemaphoreLock function work fine a= nd pass the regression tests. 1) Replace the call to WaitForMultipleObjectsEx with WaitForMultipleObjects= . 2) Handle the WAIT_IO_COMPLETION return code same as WAIT_OBJECT_0. There i= s a similar code like this in socket.c, so this change should be safe too. --_000_CEB3FA9D6450shivshiciscocom_ Content-Type: text/html; charset="us-ascii" Content-ID: <5539778C5DCF17428D8EED200D0A6AF1@emea.cisco.com> Content-Transfer-Encoding: quoted-printable

There seems to be a has a dormant bug  in PostgreSQL source code = build using VisualStudio(VS)  which shows up with the newer OS( n= ot sure if it is the OS or some other thing in the environment ). MinGW bui= ld doesn't access this code path and thus doesn't hit this bug. 

SYMPTOM: 
The following symptom is encountered in PostgreSQL build using Visual Studi= o:  PostgreSQL regression tests fail with server crashing repeatedly w= ith this message in the log file: "PANIC:  could not lock semapho= re: error code 0". The issue is encountered for VS 2005, VS 2008( 32bit and 64bit executables), VS 2010 and VS 2012 built = executables.  The issue was reproducible with PostgreSQL 6.2.3 and 6.2= .5. We didn't encounter this issue in MinGW build or EnterpriseDB Packaged = executables (which seems to have been built using VisualStudio 2010). 


CAUSE:
The PGSemaphoreLock function in postgresql-9.2.5\src\backend\port\win32_sem= a.c (https://github.com/postgres/= postgres/blob/master/src/backend/port/win32_sema.c) uses "Ex" version of "WaitForMultipleObjects" Windows = function (http://msdn.micro= soft.com/en-us/library/windows/desktop/ms687028%28v=3Dvs.85%29.aspx) however doesn't handle the additional awake calls from the "bAlertabl= e" state. Specifically, it doesn't handle the WAIT_IO_COMPLETION retur= n code when woken up by a User-mode Asynchronous Procedure Call(APC) or Asy= nc IO completion.

The part I do NOT understand is why do the User-Mode APC or Async IO comple= tion triggers get fired only in the executables we built and not in the one= s built by EnterpriseDB and bits built by other users since no one has comp= lained about it. Irrespective if it is triggered or not, the code should have handled all the return codes = of the WaitForMultipleObjectsEX API and that is the reason I think it is a = bug.

I checked the source code for calls = which will trigger the Async IO or user-mode APC(<= a href=3D"http://msdn.microsoft.com/en-us/library/windows/desktop/aa365468(= v=3Dvs.85).aspx" style=3D"text-decoration: none; font-family: 'Segoe UI Sem= ibold', 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif;= line-height: 20px; color: rgb(0, 24, 143); ">ReadFileEx,WriteFileEx, Qu= eueUserAPC) and could not find any. I am not sure what triggers the WAIT_IO_COMPLETION return call= . I could not find a way to figure out that information in the de= bug environment.

(Posible) FIX:
Either of the following changes to the PGSemaphoreLock function work fine a= nd pass the regression tests.

1) Replace the call to WaitForMultipleObjectsEx with WaitForMultipleObjects= .
2) Handle the WAIT_IO_COMPLETION return code same as WAIT_OBJECT_0. There i= s a similar code like this in socket.c, so this change should be safe too.<= /div>


--_000_CEB3FA9D6450shivshiciscocom_--