Skip to content

fix(client): handle the last retry attempt - #80

Open
Bugs5382 wants to merge 1 commit into
mainfrom
fix/71-retry-last-attempt
Open

Bugs5382 wants to merge 1 commit into
mainfrom
fix/71-retry-last-attempt

Conversation

@Bugs5382

Copy link
Copy Markdown
Owner

What and why

Connection counts reconnect attempts with _retryCount, which starts at 0 and is post-incremented in the socket close handler. With maxConnectionAttempts: N the drops see retryCount 0..N-1 and retry (N client.error events). The next drop sees retryCount === N, which matched neither retryCount < N nor retryCount > N, so the handler did nothing: no retry timer, no close, no event, and the connection stayed in CONNECTING forever. retryCount > N was unreachable, because the count never advances past N once a close happens.

The fix turns the else if (retryCount > N) into a plain else, so the attempt after the last allowed retry closes the connection. The retry count and the option's cap (1 to 50) are unchanged.

Not touched: _retryCount is reset to 1 (not 0) on a successful connect, so after a reconnect one fewer retry is allowed. That is a separate quirk and not part of #71.

Closes #71

Verification

  • Lint clean
  • Tests pass
  • Build succeeds
  • Documentation updated (if behavior or API changed)

How this was verified

  • New test in __tests__/client/hl7.client.test.ts: connect to a port nothing listens on with maxConnectionAttempts: 2; expects 2 client.error events and then a close event. It failed before the fix (2 errors, no close) and passes after.
  • npm run lint: exit 0. npm run format:check: exit 0.
  • npx vitest run __tests__/client __tests__/server: 586 passed, 2 skipped.
  • npx tsc --noEmit -p packages/node-hl7-client reports 38 errors on main already (test option typing and codec.ts); the branch has 39, the extra one being the new test's options object, same kind as the existing ones in that file.
  • Build and check:dist not run (no published-file change beyond one condition).

@Bugs5382 Bugs5382 added the fix Bug fix (fix). Patch. label Nov 15, 2026
@Bugs5382 Bugs5382 self-assigned this Nov 15, 2026
@Bugs5382
Bugs5382 marked this pull request as ready for review November 15, 2026 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Bug fix (fix). Patch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(client): retry off-by-one bug leads to dead connection

1 participant