From 0fb192f1b02dad26207a194db8e3f448ce0307df Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Thu, 15 Oct 2026 12:04:27 +0300 Subject: [PATCH] Fix CreateThread() failure checks CreateThread returns NULL on failure, not INVALID_HANDLE_VALUE. In setitimer(), a failed thread creation would silently disable all timer-based timeouts. Author: Sehrope Sarkuni Discussion: https://www.postgresql.org/message-id/CAH7T-apWWfEt+V8uLU7KXv7CMM9LoqJ1Zo2LdWmXMz=u-Ek9=w@mail.gmail.com Backpatch-through: 14 --- src/backend/port/win32/timer.c | 2 +- src/bin/pg_test_fsync/pg_test_fsync.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/backend/port/win32/timer.c b/src/backend/port/win32/timer.c index 751327ef03e..16c2114c084 100644 --- a/src/backend/port/win32/timer.c +++ b/src/backend/port/win32/timer.c @@ -103,7 +103,7 @@ setitimer(int which, const struct itimerval *value, struct itimerval *ovalue) InitializeCriticalSection(&timerCommArea.crit_sec); timerThreadHandle = CreateThread(NULL, 0, pg_timer_thread, NULL, 0, NULL); - if (timerThreadHandle == INVALID_HANDLE_VALUE) + if (timerThreadHandle == NULL) ereport(FATAL, (errmsg_internal("could not create timer thread: error code %lu", GetLastError()))); diff --git a/src/bin/pg_test_fsync/pg_test_fsync.c b/src/bin/pg_test_fsync/pg_test_fsync.c index 4b84f86e7d7..4acee17f382 100644 --- a/src/bin/pg_test_fsync/pg_test_fsync.c +++ b/src/bin/pg_test_fsync/pg_test_fsync.c @@ -50,8 +50,7 @@ do { \ #define START_TIMER \ do { \ alarm_triggered = false; \ - if (CreateThread(NULL, 0, process_alarm, NULL, 0, NULL) == \ - INVALID_HANDLE_VALUE) \ + if (CreateThread(NULL, 0, process_alarm, NULL, 0, NULL) == NULL) \ pg_fatal("could not create thread for alarm"); \ gettimeofday(&start_t, NULL); \ } while (0)