Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not reconnect when disconnect isn't clean #993

Closed
realtux opened this issue Sep 10, 2023 · 13 comments
Closed

Does not reconnect when disconnect isn't clean #993

realtux opened this issue Sep 10, 2023 · 13 comments

Comments

@realtux
Copy link

realtux commented Sep 10, 2023

Describe the bug
Reconnection works great when the connection is severed cleanly, such as when a client is disconnected remotely. However, when doing something like pulling an ethernet cable or disconnecting from wifi, the client will just hang forever. I've seen this issue on similar tools, where the issue is the keepalive mechanism is either not performing correctly or is configured incorrectly.

Logs
No logs, client hangs and outputs nothing until manually restarted.

Environment
Xubuntu, Node.js 18, latest xmpp.js.

@realtux
Copy link
Author

realtux commented Sep 10, 2023

Updated information:
Only doesn't reconnect when using xmpps:// schema on port 5223. xmpp:// on 5222 works fine.

@raucao
Copy link

raucao commented Oct 30, 2023

I just stumbled upon the same issue.

After I couldn't find an easy fix, I started implementing pings in my program, but halfway through I thought it was a bit silly patching over this from the outside, when a stated goal of the library is not having to manage connections manually. I think it should be treated as a bug, because loosing connectivity for any reason whatsoever should eventually result in an automatic reconnect.

@sonnyp
Copy link
Member

sonnyp commented Oct 30, 2023

A reproducer would be useful.

@raucao
Copy link

raucao commented Oct 30, 2023

You can just disconnect your Internet (e.g. turn off wifi) while any program using the latest npm module is running.

The simplest example would probably be the official example code in the client README, which should at least log that you're back online after a reconnect.

@realtux
Copy link
Author

realtux commented Oct 30, 2023

external ping is how i ultimately solved this, but it doesn't feel like something that a user should have to do, since reconnect logic does exist already, just not for the xmpps scheme. i spent some time looking at the code base to propose a fix, but i'm just not familiar with it so i had a hard time locating where the tcp logic is. i'll continue to investigate.

@ilya-lopukhin
Copy link

ilya-lopukhin commented Dec 4, 2023

the library is very buggy currently without the connection present. The getaddrinfo ENOTFOUND internal xmppjs error (at GetAddrInfoReqWrap.onlookup) is skipping the proper on('error') handler, propagating to the bottommost unhandledrejection handler and crashing the whole node process around it in case the connection ended abruptly

@sonnyp
Copy link
Member

sonnyp commented Jan 8, 2025

Currently, xmpp.js does not send application level keep alives

This will be implemented by #1005
server will need stream management support

@sonnyp
Copy link
Member

sonnyp commented Jan 8, 2025

@ilya-lopukhin the problem you are describing looks unrelated to this issue, please file a separate one

@sonnyp
Copy link
Member

sonnyp commented Jan 23, 2025

on main and with streamManagement enabled, we now send regular "pings" (in the form of stream management ack requests) to the server.

https://github.com/xmppjs/xmpp.js/tree/main/packages/stream-management

@sonnyp sonnyp closed this as completed Jan 23, 2025
@raucao
Copy link

raucao commented Jan 23, 2025

I wanted to verify the fix, but failed to load the client dependency directly from GitHub.

What's the recommended way for running custom versions of this monorepo's packages, that are not published on npm?

@sonnyp
Copy link
Member

sonnyp commented Jan 24, 2025

# clone xmpp.js
cd xmpp.js
make

then use npm link

@raucao
Copy link

raucao commented Jan 24, 2025

I think I already found a bug. Running this with the plain client example code (with the disconnect removed), results in this error after about 10 seconds or so:

IN
<r xmlns="urn:xmpp:sm:3"/>
OUT
<a xmlns="urn:xmpp:sm:3" h="2"/>
OUT
<r xmlns="urn:xmpp:sm:3"/>
IN
<a h="1" xmlns="urn:xmpp:sm:3"/>
TypeError: Cannot read properties of undefined (reading 'stanza')
    at ackQueue (file:///home/basti/src/xmpp.js/packages/stream-management/index.js:88:27)
    at file:///home/basti/src/xmpp.js/packages/stream-management/index.js:134:7
    at dispatch (/home/basti/src/xmpp.js/node_modules/koa-compose/index.js:42:32)
    at file:///home/basti/src/xmpp.js/packages/stream-features/index.js:13:16
    at dispatch (/home/basti/src/xmpp.js/node_modules/koa-compose/index.js:42:32)
    at file:///home/basti/src/xmpp.js/packages/stream-features/index.js:13:16
    at dispatch (/home/basti/src/xmpp.js/node_modules/koa-compose/index.js:42:32)
    at file:///home/basti/src/xmpp.js/packages/stream-features/index.js:13:16
    at dispatch (/home/basti/src/xmpp.js/node_modules/koa-compose/index.js:42:32)
    at iqHandler (file:///home/basti/src/xmpp.js/packages/iq/callee.js:59:31)
TypeError: Cannot read properties of undefined (reading 'stanza')
    at ackQueue (file:///home/basti/src/xmpp.js/packages/stream-management/index.js:88:27)
    at file:///home/basti/src/xmpp.js/packages/stream-management/index.js:134:7
    at dispatch (/home/basti/src/xmpp.js/node_modules/koa-compose/index.js:42:32)
    at file:///home/basti/src/xmpp.js/packages/stream-features/index.js:13:16
    at dispatch (/home/basti/src/xmpp.js/node_modules/koa-compose/index.js:42:32)
    at file:///home/basti/src/xmpp.js/packages/stream-features/index.js:13:16
    at dispatch (/home/basti/src/xmpp.js/node_modules/koa-compose/index.js:42:32)
    at file:///home/basti/src/xmpp.js/packages/stream-features/index.js:13:16
    at dispatch (/home/basti/src/xmpp.js/node_modules/koa-compose/index.js:42:32)
    at iqHandler (file:///home/basti/src/xmpp.js/packages/iq/callee.js:59:31)

@raucao
Copy link

raucao commented Jan 24, 2025

OK, so when I shut off my Internet, I can see the OUT messages for stream management, but it never sets the status to offline, and thus never seems to try to reconnect:

OUT
<r xmlns="urn:xmpp:sm:3"/>
OUT
<r xmlns="urn:xmpp:sm:3"/>
OUT
<r xmlns="urn:xmpp:sm:3"/>
OUT
<r xmlns="urn:xmpp:sm:3"/>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants