Skip to content

Add idle timeout to DMSG streams to prevent ephemeral port exhaustion#354

Merged
0pcom merged 1 commit intoskycoin:developfrom
0pcom:fix/stream-idle-timeout
Mar 27, 2026
Merged

Add idle timeout to DMSG streams to prevent ephemeral port exhaustion#354
0pcom merged 1 commit intoskycoin:developfrom
0pcom:fix/stream-idle-timeout

Conversation

@0pcom
Copy link
Copy Markdown
Collaborator

@0pcom 0pcom commented Mar 27, 2026

Streams that complete the handshake but never receive data would block in smux.waitRead indefinitely, holding their ephemeral port forever. Over time this exhausts all ~16K ports (49152-65535) on the Porter, causing "ephemeral port space exhausted" errors for new streams.

Fix by adding a 2-minute idle timeout (StreamIdleTimeout) that is:

  • Set as a read deadline after the stream handshake completes
  • Refreshed on every successful read, so active streams are unaffected
  • Applied on both initiating (DialStream) and responding (acceptStream)

Stale streams will time out, the caller gets an error, and the stream is closed — releasing its ephemeral port back to the pool.

Streams that complete the handshake but never receive data would block
in smux.waitRead indefinitely, holding their ephemeral port forever.
Over time this exhausts all ~16K ports (49152-65535) on the Porter,
causing "ephemeral port space exhausted" errors for new streams.

Fix by adding a 2-minute idle timeout (StreamIdleTimeout) that is:
- Set as a read deadline after the stream handshake completes
- Refreshed on every successful read, so active streams are unaffected
- Applied on both initiating (DialStream) and responding (acceptStream)

Stale streams will time out, the caller gets an error, and the stream
is closed — releasing its ephemeral port back to the pool.
@0pcom 0pcom merged commit a57dc6a into skycoin:develop Mar 27, 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