Skip to content

fix(nat): harden udp lifecycle and prepare 0.1.2 - #3

Merged
agalwood merged 2 commits into
mainfrom
fix/2165_udp_socket_lifecycle_20260919
Sep 19, 2026
Merged

agalwood merged 2 commits into
mainfrom
fix/2165_udp_socket_lifecycle_20260919

Conversation

@agalwood

Copy link
Copy Markdown
Member

Prepare @motrix/nat 0.1.2 with UDP lifecycle hardening. Network errors after bind stay within the NAT layer, pending operations settle on close, and concurrent callers share close completion. Native close also recovers when an implicit bind failure discards Node's queued cleanup.

PMP/PCP now cancels unfinished binds, retries failed binds with fresh sockets, and prevents old callbacks or reused nonces from affecting newer requests. STUN/UPnP stops sending after timeout or cancellation and releases listeners.

The reported stack in agalwood/Motrix#2165 was independently traced to TrackerProber and fixed in the app. This release adds defense to the NAT package; it does not claim that NAT caused that stack.

Validation:

  • pnpm run prepublishOnly: lint, typecheck, 433 passing tests, and build; four opt-in Docker cases skipped locally.
  • Added 29 regression cases, including real Node UDP lifecycle coverage.
  • 12 Motrix NAT integration tests passed against this built library.
  • npm pack --dry-run: only distribution files, package metadata, license, and bilingual READMEs; zero runtime dependencies.

Keep native UDP error handling active after bind, reject pending work on
error or close, and share close completion. Tolerate already-closed
handles and retry native close when an implicit bind failure discards
Node's queued close operation.

Detach PMP/PCP sockets before asynchronous teardown, cancel unfinished
binds, and recover from failed binds. Scope callbacks to their socket and
request so old sends, messages, and reused nonces cannot affect a newer
request. Stop STUN/UPnP work after timeout or abort and release listeners.

Add deterministic race coverage and real Node UDP lifecycle tests. All
433 default-suite tests pass; four opt-in Docker matrix tests are skipped.
Lint, typecheck, and build pass. Motrix's 12 NAT integration tests also pass
when loading this built library via a temporary test alias.

Related to agalwood/Motrix#2165. That issue's reported Windows stack was
fixed separately in TrackerProber; this change hardens the NAT library.
@agalwood
agalwood merged commit 5d9c840 into main Sep 19, 2026
8 checks passed
@agalwood
agalwood deleted the fix/2165_udp_socket_lifecycle_20260919 branch September 19, 2026 08:52
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