Skip to content

fix: add timeout and close handling to connection.ready()#253

Merged
ShogunPanda merged 6 commits intoplatformatic:mainfrom
tburch:fix/connection-ready-timeout
Mar 18, 2026
Merged

fix: add timeout and close handling to connection.ready()#253
ShogunPanda merged 6 commits intoplatformatic:mainfrom
tburch:fix/connection-ready-timeout

Conversation

@tburch
Copy link
Copy Markdown
Contributor

@tburch tburch commented Mar 16, 2026

Summary

  • connection.ready() registers .once('connect') and .once('error') but if neither event fires, the callback never completes — causing pool.get() and kPerformWithRetry to hang indefinitely
  • Add a timeout using the existing connectTimeout option (default 5s) so the callback is invoked with a TimeoutError if the connection doesn't become ready in time
  • Also listen for 'close' events, returning a NetworkError if the connection closes while waiting
  • Unified cleanup() function prevents listener and timer leaks across all exit paths

tburch added 2 commits March 16, 2026 14:59
If neither 'connect' nor 'error' fires while waiting in ready(),
the callback never completes, causing pool.get() and kPerformWithRetry
to hang indefinitely. This adds a timeout using the existing
connectTimeout option and also listens for 'close' events.

Signed-off-by: Tristan Burch <tristan@day.ai>
- Use host:port in timeout message when available for consistency with socket timeout
- Destroy socket when ready() timeout fires to prevent racing socket timeout from
  emitting an unhandled error event after listeners are cleaned up
- Skip timeout callback when connection is already in ERROR/CLOSED state to prevent
  double-invocation when connect() throws synchronously (e.g. invalid port)

Signed-off-by: Tristan Burch <tristan@tburch.com>
Signed-off-by: Tristan Burch <tristan@day.ai>
Copy link
Copy Markdown
Contributor

@ShogunPanda ShogunPanda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a test? The rest LGTM.

tburch added 4 commits March 17, 2026 14:24
Signed-off-by: Tristan Burch <tristan@day.ai>
Signed-off-by: Tristan Burch <tristan@day.ai>
When leaveGroup() is called during the metadata-insync phase of a
rebalance, the metadata callback in #updateAssignments() continued
unconditionally and overwrote assignments. Add a #membershipActive
guard consistent with #performJoinGroup() and #performSyncGroup().

Signed-off-by: Tristan Burch <tristan@day.ai>
@ShogunPanda ShogunPanda merged commit cb6f862 into platformatic:main Mar 18, 2026
22 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.

2 participants