Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kWLo9-00052H-Rc for pgsql-bugs@arkaria.postgresql.org; Sat, 24 Oct 2020 15:50:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kWLo8-0006Ar-D2 for pgsql-bugs@arkaria.postgresql.org; Sat, 24 Oct 2020 15:50:16 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kWLo8-0006Ai-7J for pgsql-bugs@lists.postgresql.org; Sat, 24 Oct 2020 15:50:16 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kWLo1-0002c6-Iu for pgsql-bugs@lists.postgresql.org; Sat, 24 Oct 2020 15:50:15 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 09OFo4EU367783; Sat, 24 Oct 2020 11:50:05 -0400 From: Tom Lane To: exclusion@gmail.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #16685: The ecpg thread/descriptor test fails sometimes on Windows In-reply-to: <16685-d6cd241872c101d3@postgresql.org> References: <16685-d6cd241872c101d3@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Sat, 24 Oct 2020 04:05:07 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <367781.1603554604.1@sss.pgh.pa.us> Date: Sat, 24 Oct 2020 11:50:04 -0400 Message-ID: <367782.1603554604@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk PG Bug reporting form writes: > I found that the get_descriptors() function called in ECPGdeallocate_desc > sometimes can return null. > The following debugging code inserted into the ECPGallocate_desc: > ... > shows on a failure: > TlsGetValue() returned null on iteration 209, error: 0, descriptor_key: 28, > initial descriptor_key: 0. > or > TlsGetValue() returned null on iteration: 369, error: 0, descriptor_key: 28, > initial descriptor_key: 0 Hm. I'm supposing that 0 isn't likely to be the correct TLS index, and what this is showing us is that we got here before anyone had done descriptor_key_init. I'll bet that the correct fix is static void set_descriptors(struct descriptor *value) { + pthread_once(&descriptor_once, descriptor_key_init); pthread_setspecific(descriptor_key, value); } and that you could probably reproduce this on non-Windows, too, if you tried hard (sticking a delay in get_descriptors might do it). regards, tom lane