diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2012-05-10 13:36:18 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2012-05-10 13:36:18 -0400 |
commit | 1b48f6af315e9db89aaf43e8c8c9de903294fbdf (patch) | |
tree | 358e30a37c55d3a5277f6c9a5559cdee8416246e /src | |
parent | 71ca53608de1763c0d82bf463580a30f634eba56 (diff) | |
download | postgresql-1b48f6af315e9db89aaf43e8c8c9de903294fbdf.tar.gz postgresql-1b48f6af315e9db89aaf43e8c8c9de903294fbdf.zip |
Fix Windows implementation of PGSemaphoreLock.
The original coding failed to reset ImmediateInterruptOK before returning,
which would potentially allow a subsequent query-cancel interrupt to be
accepted at an unsafe point. This is a really nasty bug since it's so hard
to predict the consequences, but they could be unpleasant.
Also, ensure that signal handlers are serviced before this function
returns, even if the semaphore is already set. This should make the
behavior more like Unix.
Back-patch to all supported versions.
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/port/win32_sema.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/backend/port/win32_sema.c b/src/backend/port/win32_sema.c index 8c364dfe88d..6602e47ffc6 100644 --- a/src/backend/port/win32_sema.c +++ b/src/backend/port/win32_sema.c @@ -121,8 +121,13 @@ PGSemaphoreLock(PGSemaphore sema, bool interruptOK) DWORD ret; HANDLE wh[2]; - wh[0] = *sema; - wh[1] = pgwin32_signal_event; + /* + * Note: pgwin32_signal_event should be first to ensure that it will be + * reported when multiple events are set. We want to guarantee that + * pending signals are serviced. + */ + wh[0] = pgwin32_signal_event; + wh[1] = *sema; /* * As in other implementations of PGSemaphoreLock, we need to check for @@ -135,20 +140,19 @@ PGSemaphoreLock(PGSemaphore sema, bool interruptOK) ImmediateInterruptOK = interruptOK; CHECK_FOR_INTERRUPTS(); - errno = 0; ret = WaitForMultipleObjectsEx(2, wh, FALSE, INFINITE, TRUE); if (ret == WAIT_OBJECT_0) { - /* We got it! */ - return; - } - else if (ret == WAIT_OBJECT_0 + 1) - { /* Signal event is set - we have a signal to deliver */ pgwin32_dispatch_queued_signals(); errno = EINTR; } + else if (ret == WAIT_OBJECT_0 + 1) + { + /* We got it! */ + errno = 0; + } else /* Otherwise we are in trouble */ errno = EIDRM; |