Skip to content

Commit f5ba023

Browse files
authored
fix: close dead connections even if they have active subscriptions (#438)
1 parent 321a9cc commit f5ba023

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

.changeset/crisp-paws-own.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"nostream": patch
3+
---
4+
5+
fix: close dead connections even if they have active subscriptions

src/adapters/web-socket-adapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export class WebSocketAdapter extends EventEmitter implements IWebSocketAdapter
126126
}
127127

128128
public onHeartbeat(): void {
129-
if (!this.alive && !this.subscriptions.size) {
129+
if (!this.alive) {
130130
logger.error(`web-socket-adapter: pong timeout for client ${this.clientId} (${this.getClientAddress()})`)
131131
this.client.close()
132132
return

test/unit/adapters/web-socket-adapter.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,15 +216,15 @@ describe('WebSocketAdapter', () => {
216216
expect(client.close).to.have.been.calledOnce
217217
})
218218

219-
it('does not close when client is not alive but has subscriptions', () => {
219+
it('closes when client is not alive even if it has active subscriptions', () => {
220220
adapter.onSubscribed('sub-1', [{ kinds: [1] }])
221221

222222
// First heartbeat: sets alive to false, pings
223223
adapter.emit(WebSocketAdapterEvent.Heartbeat)
224-
// Second heartbeat: alive is false, but has subs -> keep alive
224+
// Second heartbeat: alive is still false, has subs -> still close
225225
adapter.emit(WebSocketAdapterEvent.Heartbeat)
226226

227-
expect(client.close).not.to.have.been.called
227+
expect(client.close).to.have.been.called
228228
})
229229
})
230230

0 commit comments

Comments
 (0)