Skip to content

fix(shutdown): join GameUI workers before unloading - #6

Merged
hzqst merged 1 commit into
mainfrom
fix/gameui-socket-shutdown
Oct 6, 2026
Merged

hzqst merged 1 commit into
mainfrom
fix/gameui-socket-shutdown

Conversation

@hzqst

@hzqst hzqst commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

GameUI can terminate its socket worker from its DLL destructor while that worker owns a UCRT lock. On real HL 3266 this leaves the engine network worker blocked in normal thread cleanup, with the main thread waiting for it indefinitely.

This change joins GameUI's managed threads before the engine calls FreeLibrary, outside the loader and socket locks. The engine FreeLibrary hook now covers PE and BLOB engines across hl-, svencoop- and cof-*. Existing ServerBrowser pre-unload waiting, engine-state gates and callback-only module exclusions remain intact.

GameUI/ServerBrowser select waits are capped at 20 ms. Once termination starts, select reports no readiness and recvfrom returns WSAEWOULDBLOCK, allowing continuous nonblocking receive loops to unlock and reach their existing shutdown-event check. Both Winsock import DLL names are supported; main-thread socket calls and socket timeout options remain unchanged.

Validation:

  • MSVC x86 Debug/Release plugin builds and both CTests passed. Added coverage for real UDP idle/continuous receive shutdown, main-thread forwarding, and join-before-unload routing with engine-state gates.
  • Published gamedata validates for all 11 snapshots; no new symbols are required.
  • Real HL 3266 CDB evidence shows the GameUI worker exiting before its destructor's TerminateThread. Two map/restart/quit runs exited 0.
  • HL 10210 and CoF 5936 exit tests, and Sven 10257 map/restart/quit, exited 0. Other snapshots were not individually launched for this change.

Known validation limit: repeated HL 3266 runs also encountered heap corruption during reload and an allocator shutdown spin after both generations' network joins completed. These failures remain unresolved, so this PR does not claim consistently successful full-installation restarts. Teardown diagnostics remain debugger output because the GameUI console may already be shut down.

Follow-up to #4 and #5. Companion fixture documentation: MetaHookSv/MetaHook#5 (binary/source correspondence and remaining failures).

Co-Authored-By: Codex <codex@openai.com>
@hzqst
hzqst merged commit 15758f0 into main Oct 6, 2026
1 check passed
@hzqst
hzqst deleted the fix/gameui-socket-shutdown branch October 6, 2026 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant