Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/adapters/web-socket-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class WebSocketAdapter extends EventEmitter implements IWebSocketAdapter
}

public onHeartbeat(): void {
if (!this.alive && !this.subscriptions.size) {
if (!this.alive) {
logger.error(`web-socket-adapter: pong timeout for client ${this.clientId} (${this.getClientAddress()})`)
this.client.close()
return
Expand Down
6 changes: 3 additions & 3 deletions test/unit/adapters/web-socket-adapter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,15 @@ describe('WebSocketAdapter', () => {
expect(client.close).to.have.been.calledOnce
})

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

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

expect(client.close).not.to.have.been.called
expect(client.close).to.have.been.called
})
})

Expand Down