Skip to content

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

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

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

3 participants