Skip to content

fix: close dead connections even if they have active subscriptions#438

Open
tharu-jwd wants to merge 3 commits intocameri:mainfrom
tharu-jwd:fix/dead-connections-with-subscriptions
Open

fix: close dead connections even if they have active subscriptions#438
tharu-jwd wants to merge 3 commits intocameri:mainfrom
tharu-jwd:fix/dead-connections-with-subscriptions

Conversation

@tharu-jwd
Copy link
Copy Markdown

Description

The heartbeat was skipping termination for dead clients that had active subscriptions. Removed !this.subscriptions.size guard from onHeartbeat() as the solution.

Related Issue

Fixes #427

Motivation and Context

Dead clients with subscriptions were kept alive forever. Server kept pinging them, matching events against their filters, leaking memory.

How Has This Been Tested?

Manually connected a client, sent a REQ, killed it abruptly, confirmed the server closes it on the next heartbeat cycle instead of continuing to ping.

Screenshots (if appropriate):

N/A

Types of changes

  • Non-functional change (docs, style, minor refactor)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my code changes.
  • All new and existing tests passed.

@cameri cameri self-assigned this Apr 18, 2026
@cameri cameri requested a review from Copilot April 18, 2026 11:28
@cameri
Copy link
Copy Markdown
Owner

cameri commented Apr 18, 2026

@tharu-jwd Please address failing ci checks

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a WebSocket heartbeat cleanup bug where dead connections with active subscriptions were never terminated, causing ongoing pings, event matching work, and memory growth.

Changes:

  • Remove the !this.subscriptions.size guard so pong timeouts close dead clients even when they have active subscriptions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 131 to 135
public onHeartbeat(): void {
if (!this.alive && !this.subscriptions.size) {
if (!this.alive) {
console.error(`web-socket-adapter: pong timeout for client ${this.clientId} (${this.getClientAddress()})`)
this.client.close()
return
@cameri
Copy link
Copy Markdown
Owner

cameri commented Apr 18, 2026

@tharu-jwd commits must follow the conventional commits spec, please rebase and update your commit messages

@tharu-jwd tharu-jwd force-pushed the fix/dead-connections-with-subscriptions branch from 679cbc1 to e1bcfcf Compare April 21, 2026 12:32
@cameri cameri changed the title close dead connections even if they have active subscriptions fix: close dead connections even if they have active subscriptions Apr 21, 2026
@coveralls
Copy link
Copy Markdown
Collaborator

Coverage Status

coverage: 74.525% (-0.008%) from 74.533% — tharu-jwd:fix/dead-connections-with-subscriptions into cameri:main

@tharu-jwd
Copy link
Copy Markdown
Author

Hi @cameri
Anything else needs to be done from my side ?

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 22, 2026

🦋 Changeset detected

Latest commit: b46aa77

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
nostream Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@cameri
Copy link
Copy Markdown
Owner

cameri commented Apr 22, 2026

@tharu-jwd yes, please include a changeset file. Use npx changeset to create it.

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.

[BUG] Dead connections with active subscriptions are never cleaned up

4 participants