Skip to content

fix(download): disable uTP to prevent ENOBUFS socket exhaustion crashes - #21

Merged
kaiserc merged 1 commit into
mainfrom
fix/webtorrent-utp-enobufs
Sep 2, 2026
Merged

fix(download): disable uTP to prevent ENOBUFS socket exhaustion crashes#21
kaiserc merged 1 commit into
mainfrom
fix/webtorrent-utp-enobufs

Conversation

@kaiserc

@kaiserc kaiserc commented Sep 2, 2026

Copy link
Copy Markdown
Owner

What and why

WebTorrent's uTP implementation relies on the native \utp-native\ dependency. In \utp-native, each outgoing peer connection attempts to bind a new, independent UDP socket on an ephemeral port (
ew UTP()\ -> \uv_udp_bind(0, '0.0.0.0')) rather than multiplexing traffic over a single shared UDP socket.

Under active swarm discovery and peer reconnection churn, rapidly opening dozens to hundreds of UDP sockets exhausts the OS socket buffer space and dynamic port pool—especially on Windows, which triggers Winsock error 10055 (\WSAENOBUFS\ / \code: 'ENOBUFS', 'no buffer space available').

Furthermore, when \�inding.utp_napi_bind\ throws \ENOBUFS, \utp-native\ schedules \process.nextTick(emitError, this, err)\ on the underlying \UTP\ socket instance. Because \UTP.connect\ only returns the connection stream (\conn) without attaching an error handler to the orphaned \UTP\ socket instance, this error is emitted with 0 listeners, escalating into an unhandled \uncaughtException\ that instantly terminates the process.

This fix passes \utp: false\ to the \WebTorrent\ constructor options in \ensureClient(), forcing peer traffic over standard TCP. Standard BitTorrent TCP (BEP 3) is supported by 100% of BitTorrent clients, fully error-handled, pooled, and immune to ephemeral UDP socket buffer exhaustion.

Checklist


  • pm run typecheck\ is clean

  • pm test\ passes (586 tests across 67 test files)
  • New logic has a test (vitest; mock node built-ins for platform code)
  • OS-touching code works on Windows, macOS, and Linux
  • One concern, with a Conventional Commits title (\ eat:\ / \ ix:\ / \docs:\ / \chore:)

WebTorrent's uTP transport uses utp-native, which allocates an independent UDP socket for every outgoing peer connection attempt. Under heavy swarm discovery and peer reconnection churn, Windows rapidly exhausts socket buffer space and dynamic ports (WSAENOBUFS / ENOBUFS: 'no buffer space available').

Furthermore, when binding fails with ENOBUFS, utp-native's UTP.connect emits an 'error' event on an orphaned EventEmitter that has no error listener registered, triggering an unhandled exception that crashes the entire application.

Disabling uTP via { utp: false } instructs WebTorrent to connect to peers exclusively via standard TCP. TCP connections are universally supported by all BitTorrent clients, fully error-handled, pooled, and do not exhaust ephemeral UDP socket buffers.
@kaiserc
kaiserc merged commit 2f77675 into main Sep 2, 2026
3 checks passed
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