xmppjs / xmpp.js

XMPP for JavaScript
ISC License
2.18k stars 371 forks source link

Cannot read properties of null (reading 'once') in 'promise.js' #974

Open CamilleDrapier opened 1 year ago

CamilleDrapier commented 1 year ago

Describe the bug Upon calling client.disconnect(); I notice I sometimes having the following problem raised in promise.js

Sadly, I'm not completely sure about how to reproduce this problem as it might be related to the reconnection mechanism being triggered, or because of multiple disconnection attempts being called in parallel?

Logs

TypeError

Cannot read properties of null (reading 'once')

Crashed in non-app:
./node_modules/@xmpp/events/lib/promise.js in <anonymous>
<anonymous> in new Promise
Called from:
./node_modules/@xmpp/events/lib/promise.js in module.exports

It seems that the problem is that the socket has been reset to null (maybe while the promise was awaited?), probably by the _detachSocket method. but I'm not sure of the order of events that allow this to happen. It seems this happens while handling a timeout error from a ping we send from clients to the server in order to check if the client is indeed still connected; so maybe there was some concurrent event happing at that time leading to the socket being reset.

Environment As much as possible information about the environment running xmpp.js

browser: Chrome 109.0.0 Xmpp.js version: 0.13.1