Skip to content
Lakeland97 edited this page Oct 30, 2026 · 4 revisions

GC

A joined client does not crash; it stops inside the hxcpp Immix stop-the-world handshake. A bounded-wait patch gets it past the stall at ~6 s per frame.

That stall was observed while the client still owned the loading widget. With the loading screen removed (play, Joining) the same client joins and renders without the bounded wait. The patch below is a diagnostic for the stall, not a requirement of any shipped profile.

What was observed

Welcomed by server (Level: GameCon, Game: BP_TagGameMode_C)
SLGameState.hx:405: Game Session ID is null
Received phase: WaitingForPlayers
GamePhaseManager.BeginPlay() currentPhaseName: WaitingForPlayers
<log stops; process alive; no ticks, no 10 s Twitch checks>
  • Same stop point in every unpatched run; process alive; host holds the connection to the 600 s timeout.
  • -nullrhi client: identical stop.
  • One dump: all threads parked, no fault, no dialog; 8 of 24 sampled return addresses form one hxcpp GC stack.
  • With the 3000 ms patch: SeekPlayerController_0 valid, phase WaitingForPlayers, ~6 s per frame.

Mechanism

[INF] Read from the collector's code in the shipped image and one frozen dump; not observed end to end. In that dump the four "Haxe threads" are UE task-graph workers parked INFINITE on their work event, and 0x2e9190 (8-byte accessor body) and 0x141cf40 (function entry used as a callback argument) are not return addresses.

FUN_140533fe0 is the collector: a thread-driven rendezvous, not a suspension.

1405340fb  cmp  rcx,r15               ; per-entry loop
140534100  cmp  byte [rcx+0x184],dil  ; stop flag: 0 = running
140534107  jnz  140534119             ; 1 = parked/retired → skip
140534109  mov  rcx,[rcx+0x190]       ; the entry's stop event
140534110  or   edx,-1                ; INFINITE
140534113  call [142CC3688]           ; WaitForSingleObject
140534119  inc  esi

Latch CMPXCHG [0x143BC2530],-1 0x140534003; gc+8 taken 0x1405340D6, held across waits and the marker barrier 0x140534150; resume SetEvent(+0x198) 0x140534310..0x140534342; LeaveCriticalSection 0x140534354. Root scan FUN_140535F20: every entry with +0x38 != 0, regardless of +0x184.

Four sites signal a stop event; all are checkpoints, not exits:

path function signal site
enter free zone FUN_1405343F0 0x140534454
park FUN_140536790 0x1405367E2
SetTopOfStack teardown FUN_140537590 0x14053762A
thread destructor FUN_1405335E0 0x14053362F

Park entry: Immix allocation slow path 0x140533E31, explicit checkpoints (FUN_140539600, FUN_140536800), collector re-entry. All 26 hxcpp blocking primitives (file/fflush, Sys.sleep, sockets, mutex, deque, thread join) are inside hx::EnterGCFreeZone. Remaining exposure: native work between Haxe calls, including a pooled worker idle after its Haxe callback ([INF]).

Registration is permanent for the OS thread; nothing deregisters a bridge-attached thread on return to native code:

FUN_14012C720 (157 call sites, all Haxe glue) → FUN_14013EB90 → FUN_1404CBEF0 thunk
  → FUN_140537670 → FUN_140536C10 → FUN_140533450 (append to gc+0xf0)

An idle worker is a permanent participant whose stop event nobody signals ([INF]).

ThreadInfo

416 bytes (0x1a0), constructed by FUN_140533450:

offset size field
+0x000 8 vptr (LocalAllocator::vftable; ImmixAllocator::vftable after teardown)
+0x008 4 Immix bump pointer (page position), not a thread handle
+0x00c 4 page end
+0x010 8 mark-bitmap base
+0x018 8 block header base
+0x038 8 stack high bound (root range end)
+0x040 8 stack low / last SP (root range start)
+0x180 4 zeroed at init and attach
+0x184 1 STOP FLAG: 0 = participating, 1 = parked/retired
+0x188 4 SetTopOfStack nesting
+0x18c 4 GetCurrentThreadId(), cleared only by the exit path
+0x190 8 stop event (auto-reset), what the collector waits on
+0x198 8 resume event (auto-reset)

No thread handle, exit code or liveness marker is stored; +0x18c is written once at attach and never read by the collector. +0x08 is the allocator bump pointer, so 0x7fd0/0x15c are page offsets.

Dump: entry 1 = tid 5804, thread gone, tid never cleared, +0x184 == 0; entry 0 = tid 468, the collector (RIP ntdll!0x16f1a4, stack 0x534119 < 0x537765 < 0x535324 < 0x533eb1 < 0x7ce099 < 0x77bbcb …, from Haxe string allocation). Live tid 1348 never acknowledged its stop event; removing 5804 still froze at BeginPlay → the blocked entry is live: a missing safepoint, not a stale registration ([INF]).

Attempts, in order

# test result
1 change the polling delay / timer no effect; the wait is INFINITE
2 bound the wait to 100 ms and proceed (83 ca ff → 6a 64 5a) freeze → unique Fatal error ~66 s later; sweeping without the thread's roots is a use-after-free ([INF])
3 skip entries with tid == 0 (8 bytes, in place) safe, insufficient; the dead entry has tid 5804
4 liveness test via OpenThread/GetExitCodeThread (215-byte stub at 0x3AB7CFC, hook 0x5334FB) does not fix it; both remaining events unsignalled, 1348 live
5 bounded wait + abort before the mark, 3000 ms works: join survives, PC: SeekPlayerController_0, no fatal
6 same patch at 500 ms froze at the same BeginPlay point
7 same patch at 50 ms no ticks within 60 s
8 HXCPP_MINIMUM_WORKING_MEMORY=268435456 + HXCPP_TARGET_FREE_SPACE=268435456 identical freeze
9 1 GiB heap threshold identical freeze; the decision is never reached

The liveness test cannot work: the only guard is +0x184; a live thread at a non-checkpoint has +0x184 == 0 with an unsignalled event, so skipping it runs the mark under a mutating stack, and forcing +0x184 = 1 on attach is the same race. A no-op FUN_14013EB90 drops allocator/root registration and corrupts the heap; removing an entry inside the loop invalidates ESI/R14/[RBX+0xEC] (swap-with-last).

The bounded-wait patch

0x140534110  file 0x533510   83 CA FF FF 15 6F F5 78 02  →  E9 D2 4A 58 03 90 90 90 90   jmp 0x143AB8BE7
0x143AB8BE7  file 0x3AB7DE7  BA B8 0B 00 00  FF 15 96 AA 20 FF  85 C0  75 05  E9 1E B5 A7 FC  E9 F0 B6 A7 FC
                             mov edx,3000 / call [142CC3688] / test eax,eax / jnz abort / jmp 140534119 / jmp 1405342F0

Return: 0x140534119 on WAIT_OBJECT_0, 0x1405342F0 (latch clear, resume, leave gc+8) on timeout. Cave header: .rdata VirtualSize 0xDF5AFC → 0xDF5C00 (file 0x2C8), Characteristics 0x40000040 → 0x60000040 (file 0x2E4); PE checksum (Login). Copy diff: 37 bytes, 0 outside the intended ranges. Abort target 0x1405342F0, not 0x1405342F7 (0x2F7 inside the latch clear). With the liveness patch co-resident: keep its header edits, zero only 0x3AB7DE7..0x3AB7DFF, no attempt 3. Rows G1–G4, G11: PatchIndex.

Cost

3000 ms patch, joined client: DeltaTime 6.00, Realtime 6.02 per frame, 50 ms stalls. Two collections per failed allocation:

1405352cc  cmp  byte [143AC1B28],0   ; "use heap target"
1405352d4  movsxd rax,[rbx+0x7C]     ; pages
1405352dc  cmp  rax,[143AC1B30]      ; heap bytes vs target
1405352e3  jae  140535308            ; reached → collect
14053531f  call FUN_140533FE0        ; COLLECTION #1
140535358  call FUN_140533FE0        ; COLLECTION #2, same failed allocation

One collection costs at most one 3000 ms wait (first timed-out peer returns): 2 × 3 s matches. 3000 ms survives where 500 ms froze → the 3 s is probably not an abort; the peer takes seconds to reach its checkpoint ([INF]). Cost is then handshake latency; fix direction is fewer collections.

Levers

id VA file edit expected effect risk
A 0x1405352D4 0x5346D4 17 bytes: target load → cmp rax,0x40000000 (1 GiB) collections become a knee, not a periodic stall unbounded growth to the 2 GiB page cap
B 0x1405352E3 0x5346E3 73 23 → 90 90 never collect from the target test same, plus OOM — run: no change
D 0x140535358 0x534758 e8 83 ec ff ff → e9 12 00 00 00 halves the per-frame cost to 3 s one real collection remains — run: no change
F1 — — deregister at the end of the worker's Haxe work (CALL 0x140537AD0 from a 5-byte cave hook) removes the root cause needs a cave; re-registration must be idempotent
F2 — — wrap the pool idle wait in FUN_1405343F0 … FUN_140539530 removes the root cause site identification unfinished

Pages 32 KiB; allocator limit 65,501 pages ≈ 2.00 GiB. Bounded large target safe; "never collect" not.

HXCPP_TARGET_FREE_SPACE is a percentage, not bytes, consumed only in the post-sweep tail (0x140534218..0x14053429F), which recomputes [0x143AC1B30]. A client that never completes a collection never runs the tail: the target stays at its .data initial 40 KiB and every allocation miss collects (256 MB and 1 GiB settings change nothing). Patching [0x143AC1B30] alone fails; the next completed collection overwrites it.

Open questions

  • Count collector entries per frame; which entry pays the ~6 s is open (Cost).
  • Run the bounded wait with HXCPP_TARGET_FREE_SPACE (never tested together). A 6 s that disappears after one collection with rising RSS means the post-sweep tail ran; an unchanged 6 s means the abort always fires or the collections come from 0x140535AD3 (FUN_140535A60, unconditional) or 0x140533925 (explicit collect).
  • Unwind tid 1348 from entry 0's stack bounds while frozen: the top frame decides idle-in-pool vs lock-blocked and names the callback, selecting F1 or F2.

Related: Joining · ListenHost · PatchIndex

Clone this wiki locally