xmpp.js icon indicating copy to clipboard operation
xmpp.js copied to clipboard

Uncaught (in promise) TypeError: Cannot read properties of null (reading 'write')

Open filipw01 opened this issue 10 months ago • 4 comments

⚠ If you need help with XMPP itself, please visit https://xmpp.org/community/ instead.

It looks like socket can be possibly null while Client.write is called

Image

Error stack trace

VM4851 chunk-QKGHVZFU.js:317 Uncaught (in promise) TypeError: Cannot read properties of null (reading 'write')
    at VM4851 chunk-QKGHVZFU.js:317:23
    at new Promise (<anonymous>)
    at Client.write (VM4851 chunk-QKGHVZFU.js:312:16)
    at Client.send (VM4851 chunk-QKGHVZFU.js:302:20)
    at Client.send (VM4734 @xmpp_websocket.js:152:22)
    at Client.send (VM4733 @xmpp_client-core.js:29:46)
    at IQCaller.request (VM4737 @xmpp_iq_caller.js:93:29)
    at IQCaller._childRequest (VM4737 @xmpp_iq_caller.js:106:21)
    at IQCaller.set (VM4737 @xmpp_iq_caller.js:114:21)
    at bind (VM4743 @xmpp_resource-binding.js:19:37)

A clear and concise description of what the bug is.

@xmpp/client: 0.13.1

filipw01 avatar Jan 17 '25 15:01 filipw01

how do you reproduce? this might be a bug in your code

sonnyp avatar Jan 17 '25 15:01 sonnyp

ie - don't call send or write if you're not connected

sonnyp avatar Jan 17 '25 15:01 sonnyp

Sadly I don't have a nice reproduction. Looking at the stack trace I suspect this is originating from resource binding https://github.com/xmppjs/xmpp.js/blob/ee361dc968cde84dfb4295d840c534d36bcecfc3/packages/resource-binding/index.js#L15 perhaps some race condition when client disconnects

filipw01 avatar Jan 17 '25 15:01 filipw01

We'll need to find with certainty the source of the exception. Then understand why it is uncaught.

A good starting place is to check if a stream feature throwing results in an uncuaght exception

https://github.com/xmppjs/xmpp.js/blob/main/packages/stream-features/index.js (this is what resource biding uses so that's a good usage example

stream-features is the only module without tests so it could also benefit from that

sonnyp avatar Jan 17 '25 15:01 sonnyp

Might be solved in 0.14

otherwise feel free to reopen

sonnyp avatar Oct 29 '25 15:10 sonnyp