Re: BUG #16685: The ecpg thread/descriptor test fails sometimes on Windows
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: exclusion@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Date: 2020-10-24T15:50:04Z
Lists: pgsql-bugs
PG Bug reporting form <noreply@postgresql.org> 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
Commits
-
Fix ancient bug in ecpg's pthread_once() emulation for Windows.
- 758b45e83b50 9.5.24 landed
- 379c43bdad1d 9.6.20 landed
- f38b66ec0562 10.15 landed
- 12a73f29ff7d 11.10 landed
- bdc79ddd1079 12.5 landed
- fd048e0cb5aa 13.1 landed
- 21d36747d4fa 14.0 landed