Skip to content

Commit e1bcfcf

Browse files
committed
fix: close dead connections with active subscriptions on heartbeat timeout
1 parent 56652f3 commit e1bcfcf

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

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)