Skip to content

Commit 3c39d67

Browse files
committed
Fix crash when receiving payload that is null
1 parent 7d41a0f commit 3c39d67

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

lib/websocket.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ export class WebSocket extends EventEmitter {
9696
this.emit("close", err);
9797
if (!sock.isClosed) {
9898
await sock.close(1000).catch((e) => {
99+
// This fixes issue #12 where if sent a null payload, the server would crash.
100+
if (this.state === WebSocketState.CLOSING && sock.isClosed) {
101+
this.state = WebSocketState.CLOSED;
102+
return;
103+
}
99104
throw new WebSocketError(e);
100105
});
101106
}

0 commit comments

Comments
 (0)