Skip to content

fix hang on dfhack exit on windows - #6004

Merged
ab9rf merged 1 commit into
DFHack:developfrom
ab9rf:fix-windows-console-hang
Oct 16, 2026
Merged

ab9rf merged 1 commit into
DFHack:developfrom
ab9rf:fix-windows-console-hang

Conversation

@ab9rf

@ab9rf ab9rf commented Oct 15, 2026

Copy link
Copy Markdown
Member

This fixed a lifelong bug in the implementation of DFHack's console on WIndows: calling FreeConsole while another thread is waiting in ReadConsoleInput on the same console has undefined behavior in Windows, and recent releases of WIndows changed the behavior in a manner that is detrimental to our use.

This change adds a Windows event object that the console now waits for in parallel with the console read handle. Shutdown signals the event object, causing the console thread to exit cleanly when the core wants the console to shut down. The console never waits in ReadConsoleInput as this is only called when console input is known to be available.

The same problem would theoretically exist for Linux, but the Linux implementation has always had a pipe (used as an expensive standin for a event object as Linux doesn't have event objects that can be waited for in parallel with file handles) to yield the same result.

Fixes #6003

This fixed a lifelong bug in the implementation of DFHack's console on WIndows: calling `FreeConsole` while another thread is waiting in `ReadConsoleInput` on the same console has undefined behavior in Windows, and recent releases of WIndows _changed the behavior_ in a manner that is detrimental to our use.

This change adds a Windows event object that the console now waits for in parallel with the console read handle. Shutdown signals the event object, causing the console thread to exit cleanly when the core wants the console to shut down. The console never waits in `ReadConsoleInput` as this is only called when console input is known to be available.

The same problem would theoretically exist for Linux, but the Linux implementation has always had a pipe (used as an expensive standin for a event object as Linux doesn't have event objects that can be waited for in parallel with file handles) to yield the same result.

Fixes DFHack#6003
@TruePikachu

Copy link
Copy Markdown

I can confirm reproduction of the original bug on my desktop (Win11 w/ KB5127648 installed) with the Steam-released 53.16-r2, and that a minimal build of DFHack as of c0764b4 copied on top of the Steam DFHack location does not exhibit the bug; as far as I'm aware, this PR fixes #6003.

@ab9rf
ab9rf merged commit a3fc575 into DFHack:develop Oct 16, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants