Skip to content

fix(network): join workers before shutting down sockets - #5

Merged
hzqst merged 1 commit into
mainfrom
fix/network-shutdown-before-cleanup
Oct 6, 2026
Merged

hzqst merged 1 commit into
mainfrom
fix/network-shutdown-before-cleanup

Conversation

@hzqst

@hzqst hzqst commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Fixes #4.

The engine forcibly terminates its network worker during shutdown, which can abandon Steam locks. All 11 supported Windows binaries also close sockets before stopping the worker, while its select runs outside the network lock.

Track the exact NET_ThreadFunc worker and request cooperative exit at NET_Shutdown entry. Wait for the real thread object before forwarding to the original queue/socket cleanup. The worker exits at its unlocked Sleep(1) loop tail; a 20 ms select cap and a stop-aware NET_QueuePacket hook prevent idle waits or continuous reception from starving that boundary. Keep the targeted TerminateThread interception for other stop paths, preserve unrelated threads and original cleanup, and support repeated shutdown/recreation. The change also corrects manager-owned handle reclamation and waits outside the manager list lock.

Validation:

  • Win32 Debug and Release plugin builds and both CTest tests passed. The resource-order regression failed before the entry wait was implemented, then passed.
  • Handler tests use real Win32 threads, sockets, locks and waits: 100 stop/recreate cycles, idle select, continuous packets, resource closure after join, repeated/disabled shutdown, creation failure, suspended creation, unrelated termination and handle ownership/reclamation. The standalone host API only stubs fatal diagnostics; live tests cover actual hook installation.
  • Verified shutdown/worker binary paths and all 11 gamedata snapshots. Linux binaries were cross-checked, but this plugin targets Windows only.
  • Latest live runs: Sven 10257 passed 8 cases including input commands, disconnect, restart and disabled networking; HL 10210, HL 3266 BLOB and CoF 5936 each passed shutdown with exit code 0. Threaded runs logged completion before original resource cleanup. Temporary game files/configuration were restored.
  • Remaining snapshots have static/catalog coverage only. An earlier CoF input-command scenario lost RCON before quit; its dump was retained and that scenario is not claimed as passing.

Release dependencies:

  • Publish the upstream NET_QueuePacket symbols from feat(symbols): add NET_QueuePacket for all Windows engines HLND2T/GoldSrc_VibeSignatures#340. NET_Shutdown is already available; the consumer manifest now requires it.
  • BLOB engines require the companion MetaHook LoadBlob.cpp ordinal-import fix so named select queries find ordinal imports. That core change is currently local and is not included in this PR; BLOB live verification used the patched launcher. Do not release BLOB support without it.
  • Local validation used the generated and validated candidate catalog; publish upstream before relying on normal remote gamedata synchronization.

Co-Authored-By: Codex <codex@openai.com>
@hzqst
hzqst merged commit 4afeeac into main Oct 6, 2026
1 of 2 checks passed
@hzqst
hzqst deleted the fix/network-shutdown-before-cleanup branch October 6, 2026 14:20
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.

Plan:接管网络线程 TerminateThread,在安全 Sleep 边界协作退出并等待结束

1 participant