xmppjs / xmpp.js

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

How to restart xmpp client on network reconnect? #874

Closed duskload closed 3 years ago

duskload commented 3 years ago

I'am using react-native and ejjaberd xmpp server

On network connection lost, if I send a message to another user, it will be sent only in 1-2 minutes when the stream is restored (probably via a keepalive -- not stream management).

Is there a way to speed things up? I have stream management enabled (as I understood it is enabled by default now, and I see that client.streamManagement.enabled is set to true), but It doesn't seem to affect anything. Is this normal? How can we check that stream management is restoring the session. And if not, why?

Xmpp.js version: 0.12.0 RN version: 0.61.2 Ejabberd version: 4.1905.13

Both android and iOS. IOS: 11 - 14 Android: 8 - 10

duskload commented 3 years ago

Hi @sonnyp, can you help with this? Or maybe some additional info is needed or description is unclear?

sonnyp commented 3 years ago

Hello, there is a lot of moving parts, and it would be useful to share more details; for example

xmpp.js version react native version ejabbed version android? ios? both? which versions ?

Do you do anything special to alter @xmpp/client default configuration?

On network connection lost,

What kind of network connection lost? How do you reproduce?

I understood it is enabled by default now, and I see that client.streamManagement.enabled is set to true

Counterintuitive but It doesn't mean it is enabled. Your server may not support it. Please check if that's the case.


Regardless of stream management the issue might be unrelated - it shouldn't take so long.

Here is how you can help me help you :)

Please reproduce the problem and share the output of https://github.com/xmppjs/xmpp.js/tree/master/packages/debug please If it doesn't help identify the issue I will ask a minimal reproducible test case.

FYI I have used xmpp.js on react native with stream management and ejabberd without issues.

duskload commented 3 years ago

@sonnyp Thanks a lot for your response!

xmpp.js version react native version ejabbed version android? ios? both? which versions ?

Updated issue descriptions with versions.

Do you do anything special to alter @xmpp/client default configuration?

No

What kind of network connection lost? How do you reproduce?

Wifi connection drop, and in a minute - reconnect.

Counterintuitive but It doesn't mean it is enabled. Your server may not support it. Please check if that's the case.

I'm quite sure it is enabled and works, it will be seen in logs

<open xmlns="urn:ietf:params:xml:ns:xmpp-framing" id="10514675371920252973" version="1.0" xml:lang="en" from="chat.app.com”/>

<stream:features xmlns:stream="http://etherx.jabber.org/streams" xmlns="http://etherx.jabber.org/streams">
  <mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl">
    <mechanism>PLAIN</mechanism>
    <mechanism>SCRAM-SHA-1</mechanism>
    <mechanism>X-OAUTH2</mechanism>
  </mechanisms>
  <register xmlns="http://jabber.org/features/iq-register"/>
  <push xmlns="p1:push"/>
  <rebind xmlns="p1:rebind"/>
</stream:features>

<auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="PLAIN">
  <hidden xmlns="xmpp.js"/>
</auth>

<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/>

<open xmlns="urn:ietf:params:xml:ns:xmpp-framing" id="17338416107746835125" version="1.0" xml:lang="en" from="chat.app.com"/>

<stream:features xmlns:stream="http://etherx.jabber.org/streams" xmlns="http://etherx.jabber.org/streams">
  <bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"/>
  <session xmlns="urn:ietf:params:xml:ns:xmpp-session">
    <optional/>
  </session>
  <c ver="SJSmfSQYyDmvtW6FcwOWLg0jnv0=" node="http://www.process-one.net/en/ejabberd/" hash="sha-1" xmlns="http://jabber.org/protocol/caps"/>
  <sm xmlns="urn:xmpp:sm:2"/>
  <sm xmlns="urn:xmpp:sm:3"/>
  <csi xmlns="urn:xmpp:csi:0"/>
</stream:features>

<resume xmlns="urn:xmpp:sm:3" h="17" previd="g2gCbQAAABk5NTcyOTM3MDI5OTc5OTAwMTY3MTA4MDgyaANiAAAGS2IACMKFYgAHht8="/>

<resumed previd="g2gCbQAAABk5NTcyOTM3MDI5OTc5OTAwMTY3MTA4MDgyaANiAAAGS2IACMKFYgAHht8=" h="16" xmlns="urn:xmpp:sm:3"/>

<r xmlns="urn:xmpp:sm:3"/>
<a xmlns="urn:xmpp:sm:3" h="17"/>
<presence id="h8rdtyn8i4" xmlns="jabber:client"/>

<message xmlns="jabber:client" xml:lang="en" to="4f68d9a00298820111de@chat.app.com" from="5460c8bf4c040f5d55b8@chat.app.com/cE5h7RVsCjs:APA91bEja0pyiDwbUZRAgLwlehj90-Pt2fpojDkU1ealfxOHrJx6Cywy49mlO1deYcB10YWG4CaNsVw8sE0-3syK82K3vs5VnSbj-O9imGd5QBf0cg9l5L-ic1quhduzobheZWSJApHL" type="chat" id="73wq6om4tu">
  <archived xmlns="urn:xmpp:mam:tmp" by="4f68d9a00298820111de@chat.app.com" id="1611574154200720"/>
  <stanza-id xmlns="urn:xmpp:sid:0" by="4f68d9a00298820111de@chat.app.com" id="1611574154200720"/>
  <request xmlns="urn:xmpp:receipts"/><markable xmlns="urn:xmpp:chat-markers:0"/>
  <active xmlns="http://jabber.org/protocol/chatstates"/>
  <x xmlns="p1:push:custom" key="aps.alert.title" value="Meghan Hatalla"/>
  <x xmlns="p1:push:custom" key="aps.category" value="message"/>
  <x xmlns="p1:push:custom" key="aps.thread-id" value="5460c8bf4c040f5d55b8@chat.app.com"/>
  <x xmlns="p1:push:custom" key="toJid" value="4f68d9a00298820111de@chat.app.com"/>
  <x xmlns="p1:pushed"/>
  <delay xmlns="urn:xmpp:delay" from="chat.app.com" stamp="2021-01-25T11:29:14.218542Z">
    Offline Storage
  </delay>
  <body>Test message</body>
</message>

<message id="x3afp1s9rr" to="5460c8bf4c040f5d55b8@chat.app.com/cE5h7RVsCjs:APA91bEja0pyiDwbUZRAgLwlehj90-Pt2fpojDkU1ealfxOHrJx6Cywy49mlO1deYcB10YWG4CaNsVw8sE0-3syK82K3vs5VnSbj-O9imGd5QBf0cg9l5L-ic1quhduzobheZWSJApHL" xmlns="jabber:client">
  <received xmlns="urn:xmpp:receipts" id="73wq6om4tu"/>
</message>

<r xmlns="urn:xmpp:sm:3"/>
<a xmlns="urn:xmpp:sm:3" h="18"/>

<presence xmlns="jabber:client" xml:lang="en" to="4f68d9a00298820111de@chat.app.com/9572937029979900167108082" from="4f68d9a00298820111de@chat.app.com/9572937029979900167108082" id="h8rdtyn8i4">
  <x xmlns="vcard-temp:x:update"/>
</presence>

<presence xmlns="jabber:client" xml:lang="en" to="4f68d9a00298820111de@chat.app.com/9572937029979900167108082" from="5460c8bf4c040f5d55b8@chat.app.com/cE5h7RVsCjs:APA91bEja0pyiDwbUZRAgLwlehj90-Pt2fpojDkU1ealfxOHrJx6Cywy49mlO1deYcB10YWG4CaNsVw8sE0-3syK82K3vs5VnSbj-O9imGd5QBf0cg9l5L-ic1quhduzobheZWSJApHL" id="wzf8rcqzt8">
  <x xmlns="vcard-temp:x:update">
    <photo>8ab6d97cba7c8c9ff2a28848530bd30841798dd5</photo>
  </x>
  <delay from="5460c8bf4c040f5d55b8@chat.app.com/cE5h7RVsCjs:APA91bEja0pyiDwbUZRAgLwlehj90-Pt2fpojDkU1ealfxOHrJx6Cywy49mlO1deYcB10YWG4CaNsVw8sE0-3syK82K3vs5VnSbj-O9imGd5QBf0cg9l5L-ic1quhduzobheZWSJApHL" stamp="2021-01-25T11:30:44.838529Z" xmlns="urn:xmpp:delay"/>
</presence>

<r xmlns="urn:xmpp:sm:3"/>
<a xmlns="urn:xmpp:sm:3" h="20"/>

In a given example I do the following:

  1. Connect client (client 1)
  2. Disable wifi (client 1 lost connection)
  3. Send a message to client 1 from client 2
  4. Reconnect wifi

As I see from logs, stream reconnect was instant, but the message from a client 2 only appears in a minute or two. Could you clarify, what should be done to receive message from client two after stream reconnect? Perhaps I should send presence stanza?

sonnyp commented 3 years ago

Ejabberd version: 4.1905.13

As far as I can tell there is no such thing as ejabberd 4

I'm quite sure it is enabled and works, it will be seen in logs

Thanks for logs, stream management is enabled indeed. Would have been handy to get the timestamps for each stanza to see where the delay is - maybe I will add that to @xmpp/debug. Also direction for each stanza is missing.

As I see from logs, stream reconnect was instant, but the message from a client 2 only appears in a minute or two.

So it's not an issue with xmpp.js - either it's at protocol level or with your server

Could you clarify, what should be done to receive message from client two after stream reconnect?

So you are aware it's not an issue with xmpp.js itself? Not super cool to seek support here if that's the case.

https://stackoverflow.com/questions/tagged/ejabberd?sort=newest https://xmpp.org/community/

Perhaps I should send presence stanza?

Looks like you already do <presence id="h8rdtyn8i4" xmlns="jabber:client"/> ?

duskload commented 3 years ago

So it's not an issue with xmpp.js - either it's at protocol level or with your server So you are aware it's not an issue with xmpp.js itself? Not super cool to seek support here if that's the case.

I wasn't sure that it's not an xmpp issue, that's why I've added this issue on the first place. Thanks for you help!

Looks like you already do ?

I do, but for some reason it doesn't work consistently enough

sonnyp commented 3 years ago

You're welcome.

Please post an update here when you find the solution - it might help others.

Feel free to let me know if it happens to be an issue with xmpp.js