Skip to content

Bound connecting and requests, and clean up on close - #4

Merged
2rdzy merged 2 commits into
masterfrom
fix/timeouts-and-lifecycle
Oct 6, 2026
Merged

2rdzy merged 2 commits into
masterfrom
fix/timeouts-and-lifecycle

Conversation

@2rdzy

@2rdzy 2rdzy commented Oct 5, 2026

Copy link
Copy Markdown
Owner

Builds on the test harness in #1 (merge that first).

  • Enforce the connect timeout. The socket's timeout event was never handled (and the TLS wrapper did not forward it), so a stalled connection or TLS handshake hung. Destroy the socket on timeout, fail connect if the socket closes first, and keep the timeout armed until the connection (for TLS, the handshake) is established. Option connectTimeout, default 5000 ms.
  • Give up if the server accepts the connection but never answers server.version.
  • Add an optional requestTimeout (milliseconds, off by default) that fails a request which gets no reply and forgets its callback.
  • close() rejects pending requests (they used to hang for ever), cancels the reconnect and keep-alive timers, and stops reconnecting through a flag instead of replacing methods. Timers no longer keep the process alive: a child process test checks it exits by itself after close().
  • TlsSocketWrapper: write before connect throws a clear error, end/destroy are harmless, removing an unknown listener no longer removes all listeners, and timeout is forwarded.

Against the old code the lifecycle tests time out.

2rdzy added 2 commits October 5, 2026 22:14
Add node:test tests against a small in-process Electrum server over TCP and
TLS (with a committed, test-only certificate), covering requests, errors,
concurrency, batches, notifications and close. Run them in CI on Node 18, 20
and 22.

Point the repository, bugs and homepage fields at this fork, require Node 18
or later, and publish only index.js and lib.
- Enforce the connect timeout: the socket's 'timeout' event was never
  handled (and not forwarded by the TLS wrapper), so a stalled connection or
  TLS handshake hung. Destroy the socket on timeout, fail connect if the
  socket closes first, and keep the timeout armed until the connection (for
  TLS, the handshake) is established. Option connectTimeout, default 5000 ms.
- Give up if the server accepts the connection but never answers
  server.version, instead of waiting for ever.
- Add an optional requestTimeout (milliseconds, off by default) that fails a
  request which gets no reply and forgets its callback.
- close() now rejects pending requests, cancels the reconnect and keep-alive
  timers, and stops reconnecting through a flag instead of replacing methods.
  Timers no longer keep the process alive.
- TlsSocketWrapper: write before connect throws a clear error, end and
  destroy are harmless, removing an unknown listener no longer removes all
  listeners, and 'timeout' is forwarded.
@2rdzy
2rdzy merged commit 688045b into master Oct 6, 2026
4 of 6 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