Skip to content

Commit

Permalink
Merge pull request #9 from tallarium/fix-crash-op-in-progress-when-ws…
Browse files Browse the repository at this point in the history
…-closing

Fix crash when ws has an operation in progress while closing
  • Loading branch information
vlad-iliescu-tallarium authored Sep 13, 2022
2 parents d266447 + b45ca31 commit acc86e4
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Socket/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,17 +292,19 @@ export const makeSocket = ({
clearInterval(keepAliveReq)
clearTimeout(qrTimer)

ws.removeAllListeners('close')
ws.removeAllListeners('error')
ws.removeAllListeners('open')
ws.removeAllListeners('message')

if(ws.readyState !== ws.CLOSED && ws.readyState !== ws.CLOSING) {
try {
ws.close()
} catch{ }
}

process.nextTick(() => {
ws.removeAllListeners('close')
ws.removeAllListeners('error')
ws.removeAllListeners('open')
ws.removeAllListeners('message')
});

ev.emit('connection.update', {
connection: 'close',
lastDisconnect: {
Expand Down

0 comments on commit acc86e4

Please sign in to comment.