Skip to content

BUG-135 - Harden Final RC1 Runtime Stabilization Edges

Summary

Fix the concrete RC1 stabilization findings selected after the final hot-path C++ review. The fixes address completion shutdown ordering, runtime NAT mapping fallback hangs, accepted TCP socket allocation cleanup, server socket create failure cleanup, and bounded Arr compatibility search cache retention.

Findings Addressed

  • Part-file completion workers could move a completed file and delete .part.met before the UI thread applied TM_FILECOMPLETED, while shutdown saved known.met first.
  • UPnP/PCP/NAT-PMP timeout fallback still used an unbounded owner-lifetime wait outside process shutdown, allowing the UI thread to hang on a stuck gateway or third-party NAT library call.
  • Conditional TCP accept owned a raw accepted SOCKET before allocating the CClientReqSocket wrapper, so low-memory allocation failure could leak the accepted handle.
  • Server connect ignored Create() failure before ConnectTo(), leaving retry and cleanup paths to reason about a socket that never entered the async connect state.
  • Arr-compatible search caching expired entries only when the same key was queried again, allowing cold stale result vectors to accumulate over long controller sessions.

Acceptance Criteria

  • [x] Shutdown drains part-file completion workers and pumps posted completion finalization before known.met persistence starts.
  • [x] Runtime NAT mapping timeout/fallback uses a bounded owner-lifetime wait, abandons stuck discovery owners instead of blocking the UI, suppresses stale worker result posts, and starts fallback attempts with a fresh timeout.
  • [x] Accepted raw TCP sockets are closed if client socket wrapper allocation fails.
  • [x] Server socket Create() failure is logged, removed from open-socket tracking, and routed through the appropriate retry/stop path immediately.
  • [x] Arr compatibility cache purges expired entries on store and enforces a hard entry cap.

Implementation Evidence

  • d64b1c15 BUG-135 drain completions before known save
  • d5bc2a0d BUG-135 bound UPnP fallback waits
  • 967d69a8 BUG-135 close accepted sockets on wrapper allocation failure
  • 20a5001b BUG-135 clean up failed server socket creation
  • 7e1cb1fa BUG-135 bound Arr compatibility cache

Validation Evidence

  • git diff --check
  • Source normalization scan for touched app files.
  • Debug x64 app build through python -m emule_workspace build app --variant main --config Debug --platform x64 --build-output-mode ErrorsOnly at 20260529T100546Z-build-app.
  • Release x64 app build through python -m emule_workspace build app --variant main --config Release --platform x64 --build-output-mode ErrorsOnly at 20260529T100556Z-build-app.