Skip to content

servers: add option to build without window handler (Windows) - #22496

Closed
vszakats wants to merge 8 commits into
curl:masterfrom
vszakats:s-w-wnd-hnd
Closed

vszakats wants to merge 8 commits into
curl:masterfrom
vszakats:s-w-wnd-hnd

Conversation

@vszakats

@vszakats vszakats commented Aug 5, 2026 •

Copy link
Copy Markdown
Member

curl already built like this in UWP mode; add a macro to allow building
regular Win32 targets too, meaning without the hidden GUI window, window
handler, and thus without support for shutting down servers.exe
gracefully. To test the server in CI as a plain console app and remove
one component/variable from the system, in an effort chasing flaky runs.

The graceful option was used by taskkill (without -f) in runtests,
and it has been disabled (in favor of always -f (forced) kill), in an
attempt to avoid taskkill hanging. Those resolved, but general CI
flakiness remained. We see taskkill invoked seldom per job, and in
most of these cases it doesn't find the PID requested. It means the
graceful option is not actually used since 2025-04, and rather rarely
before that. Also just today, the callback and main loop received a few
updates to avoid potentially unsafe calls and interaction with the ctrl
handler.

Not expecting anything breakthrough here. Also graceful shutdown
is a useful feature to cleanup properly and to be in sync with other
platforms.

Also: GHA/windows: enable in Windows CI jobs.

Ref: https://learn.microsoft.com/windows/console/registering-a-control-handler-function#listen-with-hidden-window-example

Follow-up to 7db9947 #22045
Follow-up to 9ea4881 #22487
Follow-up to b11e002 #22495
Follow-up to 208b877 #21039
Follow-up to f450f38 #19897
Follow-up to 2701ac6 #19421
Follow-up to 4e203f6 #17054


Note: this may interact with #22487, which aims to simplify signal
handling and removes a raise() call in favor of a direct function
call to trigger shutdown in the window handler. It also interacts with
#22495 (and its history PRs) which enables/disables the use of taskkill
in CI runtests. It may also interact with #22045, which aims to remove
potentially unsafe calls made from handlers, amonst them the window
handler, and the window event processing loop.

@vszakats
vszakats marked this pull request as draft August 5, 2026 14:12
@github-actions github-actions Bot added tests CI Continuous Integration labels Aug 5, 2026
@vszakats vszakats added the Windows Windows-specific label Aug 5, 2026
@vszakats

vszakats commented Aug 5, 2026 •

Copy link
Copy Markdown
Member Author

It's a "Error: Process completed with exit code 2304." right away in the top flaky
Windows torture job, with the window handler disabled, in a job where taskkill
is currently disabled. → Because the window handler was aiming to fix behavior
with taskkill, this job isn't a useful combo to test this PR.

https://github.com/curl/curl/actions/runs/31014017506/job/92333286063?pr=22496

@vszakats

vszakats commented Aug 5, 2026 •

Copy link
Copy Markdown
Member Author

A more closely related PR was 4e203f6 #17054,
which dropped the gentle taskkill method on Windows a year ago, due to observing hangs
on those taskkills in CI. It means the method disabled in this PR isn't actually used, and
thus seems safe to retire unconditionally.

edit: or perhaps give the gentle kill another chance after #22487?

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a build-time switch to disable the Win32 hidden-window message loop used by the test servers on Windows, enabling the servers to run as plain console apps (including in CI) while keeping UWP behavior consistent.

Changes:

  • Introduces/uses CURL_NO_WIN32_WND to compile out the hidden window + message loop on Windows (tests/server/util.c).
  • Makes UWP builds implicitly behave as “no Win32 window handler” via a compatibility define (tests/server/util.c).
  • Updates Windows CI jobs to compile with -DCURL_NO_WIN32_WND (.github/workflows/windows.yml).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
tests/server/util.c Adds CURL_NO_WIN32_WND gating for the hidden window/thread used for WM_CLOSE-based termination.
.github/workflows/windows.yml Forces CI builds to define CURL_NO_WIN32_WND so servers run without the hidden window handler.
Suppressed comments (1)

tests/server/util.c:643

  • WaitForSingleObjectEx() returns WAIT_OBJECT_0 (0) on success, so the current if(WaitForSingleObjectEx(...)) condition skips the success path and can leak thread_main_window (and, with bAlertable=TRUE, may also treat WAIT_IO_COMPLETION as success and close the handle before the thread has exited). Consider looping past WAIT_IO_COMPLETION and explicitly checking for WAIT_OBJECT_0 before closing the handle and clearing the IDs.
      if(WaitForSingleObjectEx(thread_main_window, INFINITE, TRUE)) {
        if(CloseHandle(thread_main_window)) {
          thread_main_window = NULL;
          thread_main_id = 0;
        }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@vszakats

vszakats commented Aug 6, 2026 •

Copy link
Copy Markdown
Member Author

That's what Copilot generated as a low-confidence report. They are often legit. (it's also unrelated to the change in this PR, I mean besides disabling this partical code in CI)

tests/server/util.c:643
WaitForSingleObjectEx() returns WAIT_OBJECT_0 (0) on success, so the current if(WaitForSingleObjectEx(...)) condition skips the success path and can leak thread_main_window (and, with bAlertable=TRUE, may also treat WAIT_IO_COMPLETION as success and close the handle before the thread has exited). Consider looping past WAIT_IO_COMPLETION and explicitly checking for WAIT_OBJECT_0 before closing the handle and clearing the IDs.

      if(WaitForSingleObjectEx(thread_main_window, INFINITE, TRUE)) {
        if(CloseHandle(thread_main_window)) {
          thread_main_window = NULL;
          thread_main_id = 0;
        }

@vszakats
vszakats force-pushed the s-w-wnd-hnd branch 2 times, most recently from d1a2e35 to 3d69669 Compare August 6, 2026 23:02
@vszakats

vszakats commented Aug 6, 2026

Copy link
Copy Markdown
Member Author

FTR, this too:

7015345 [main] sh 29178 dofork: child -1 - forked process 9624 died unexpectedly, retry 0, exit code 0xC0000142, errno 11
sh: fork: retry: Resource temporarily unavailable
7004039 [main] sh 29180 dofork: child -1 - forked process 1960 died unexpectedly, retry 0, exit code 0xC0000142, errno 11
sh: fork: retry: Resource temporarily unavailable

https://github.com/curl/curl/actions/runs/31130275362/job/92717389767?pr=22496

@vszakats
vszakats marked this pull request as draft August 7, 2026 06:43
@vszakats

vszakats commented Aug 7, 2026 •

Copy link
Copy Markdown
Member Author

Letting this sit for a few days to see if previous changes made any difference.

@vszakats
vszakats marked this pull request as ready for review August 7, 2026 20:25
But, when using vcpkg with cmake, it seems that the configuration display
ends up not showing certain settings, that were actually passed through the
command-line.
@vszakats vszakats closed this in 3b0cb22 Aug 11, 2026
@vszakats
vszakats deleted the s-w-wnd-hnd branch August 11, 2026 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI Continuous Integration on-hold tests Windows Windows-specific

Development

Successfully merging this pull request may close these issues.

2 participants