aboutsummaryrefslogtreecommitdiff
path: root/src/backend/port/win32/signal.c
diff options
context:
space:
mode:
authorThomas Munro <tmunro@postgresql.org>2021-12-10 16:13:14 +1300
committerAndrew Dunstan <andrew@dunslane.net>2024-11-08 09:34:00 +1030
commit1bf47d89776c2647d896f308687fa13d6c2877e2 (patch)
treeb1b64058f041d0e45dcda4aca38e87999f981e25 /src/backend/port/win32/signal.c
parent344ac149cfdfc1efe1608f46f40f05f4af91c8eb (diff)
downloadpostgresql-1bf47d89776c2647d896f308687fa13d6c2877e2.tar.gz
postgresql-1bf47d89776c2647d896f308687fa13d6c2877e2.zip
Check for STATUS_DELETE_PENDING on Windows.
1. Update our open() wrapper to check for NT's STATUS_DELETE_PENDING and translate it to Unix-like errors. This is done with RtlGetLastNtStatus(), which is dynamically loaded from ntdll. A new file win32ntdll.c centralizes lookup of NT functions, in case we decide to add more in the future. 2. Remove non-working code that was trying to do something similar for stat(), and just reuse the open() wrapper code. As a side effect, stat() also gains resilience against "sharing violation" errors. 3. Since stat() is used very early in process startup, remove the requirement that the Win32 signal event has been created before pgwin32_open_handle() is reached. Instead, teach pg_usleep() to fall back to a non-interruptible sleep if reached before the signal event is available. This could be back-patched, but for now it's in master only. The problem has apparently been with us for a long time and generated only a few complaints. Proposed patches trigger it more often, which led to this investigation and fix. Reviewed-by: Andres Freund <andres@anarazel.de> Reviewed-by: Alexander Lakhin <exclusion@gmail.com> Reviewed-by: Juan José Santamaría Flecha <juanjo.santamaria@gmail.com> Discussion: https://postgr.es/m/CA%2BhUKGJz_pZTF9mckn6XgSv69%2BjGwdgLkxZ6b3NWGLBCVjqUZA%40mail.gmail.com (cherry picked from commit e2f0f8ed251d02c1eda79e1ca3cb3db2681e7a86) Author: Thomas Munro <tmunro@postgresql.org> Author: Alexandra Wang <alexandra.wang.oss@gmail.com>
Diffstat (limited to 'src/backend/port/win32/signal.c')
-rw-r--r--src/backend/port/win32/signal.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/backend/port/win32/signal.c b/src/backend/port/win32/signal.c
index 580a517f3f5..61f06a29f6d 100644
--- a/src/backend/port/win32/signal.c
+++ b/src/backend/port/win32/signal.c
@@ -52,7 +52,17 @@ static BOOL WINAPI pg_console_handler(DWORD dwCtrlType);
void
pg_usleep(long microsec)
{
- Assert(pgwin32_signal_event != NULL);
+ if (unlikely(pgwin32_signal_event == NULL))
+ {
+ /*
+ * If we're reached by pgwin32_open_handle() early in startup before
+ * the signal event is set up, just fall back to a regular
+ * non-interruptible sleep.
+ */
+ SleepEx((microsec < 500 ? 1 : (microsec + 500) / 1000), FALSE);
+ return;
+ }
+
if (WaitForSingleObject(pgwin32_signal_event,
(microsec < 500 ? 1 : (microsec + 500) / 1000))
== WAIT_OBJECT_0)