postgresql/src/backend/port
Tom Lane df44e411c0 Fix race condition in our Windows signal emulation.
pg_signal_dispatch_thread() responded to the client (signal sender)
and disconnected the pipe before actually setting the shared variables
that make the signal visible to the backend process's main thread.
In the worst case, it seems, effective delivery of the signal could be
postponed for as long as the machine has any other work to do.

To fix, just move the pg_queue_signal() call so that we do it before
responding to the client.  This essentially makes pgkill() synchronous,
which is a stronger guarantee than we have on Unix.  That may be
overkill, but on the other hand we have not seen comparable timing bugs
on any Unix platform.

While at it, add some comments to this sadly underdocumented code.

Problem diagnosis and fix by Amit Kapila; I just added the comments.

Back-patch to all supported versions, as it appears that this can cause
visible NOTIFY timing oddities on all of them, and there might be
other misbehavior due to slow delivery of other signals.

Discussion: https://postgr.es/m/32745.1575303812@sss.pgh.pa.us
2019-12-09 15:03:52 -05:00
..
aix Remove useless whitespace at end of lines 2010-11-23 22:34:55 +02:00
darwin pgindent run for 9.4 2014-05-06 12:12:18 -04:00
dynloader Spelling fixes 2017-03-14 13:45:54 -04:00
hpux Redefine Datum as uintptr_t, instead of unsigned long. 2009-12-31 19:41:37 +00:00
tas Update copyright for 2016 2016-01-02 13:33:40 -05:00
win32 Fix race condition in our Windows signal emulation. 2019-12-09 15:03:52 -05:00
.gitignore Combine win32 and unix latch implementations. 2016-03-21 11:03:26 +01:00
atomics.c Fix and improve pg_atomic_flag fallback implementation. 2018-04-06 20:02:02 -07:00
Makefile Combine win32 and unix latch implementations. 2016-03-21 11:03:26 +01:00
posix_sema.c Update copyright for 2016 2016-01-02 13:33:40 -05:00
sysv_sema.c Update copyright for 2016 2016-01-02 13:33:40 -05:00
sysv_shmem.c Cope with EINVAL and EIDRM shmat() failures in PGSharedMemoryAttach. 2019-05-10 14:56:41 -04:00
win32_sema.c Update copyright for 2016 2016-01-02 13:33:40 -05:00
win32_shmem.c Consistently test for in-use shared memory. 2019-04-12 22:39:52 -07:00