0

I am using MongooseIM as chat server and connecting it over websocket using xmpp.js inside react-native application. The server forcefully closes the connection after 60s on inactivity. I want to know:

  1. If this is the default config?
  2. Should/Can I change it?
  3. Should I set up ping mechanism such that my client must send some pings after every 60s to avoid disconnect
Shubham1164
  • 357
  • 6
  • 16
  • Do you have mod_ping aka XMPP Ping enabled on the server, but not on the client? 60 seconds is the default ping interval for both MongooseIM and ejabberd, so it seems a likely culprit. – erszcz Nov 14 '18 at 10:47
  • Yes, i have tried the mod_ping module. But the connection always closes irrespective of mod_ping used or not inside the chrome browser and sometimes in the react-native apps also. Don't know why? – Shubham1164 Nov 14 '18 at 11:52
  • I guess this is some limitation or safety factor for web socket conn. Not sure – Shubham1164 Nov 14 '18 at 11:53
  • TCP connections being closed might stem from a lot of factors, e.g. your network environment. Are you running the server on Amazon? If yes, this might apply to your case - https://stackoverflow.com/a/48764819/1325207. What @michalwski says below might also apply. – erszcz Nov 14 '18 at 14:12

1 Answers1

2

WebSocket connections have default timeout value for inactivity set to infinity. Your configuration most probably contains "{timeout, 60000}" in the "mod_websockets" configuration. In order to keep idle connections connected to the server you can send WebSocket ping frames from time to time.

More info about "mod_websockets" configuration is here:: https://mongooseim.readthedocs.io/en/latest/advanced-configuration/Listener-modules/#http-based-services-bosh-websocket-rest-ejabberd_cowboy

You can even configure the server to send WebSocket's ping frames by specifying the option {ping_rate, ValueInMilliSeconds}

Mickaël Rémond
  • 9,035
  • 1
  • 24
  • 44
michalwski
  • 359
  • 1
  • 3
  • Hi erszcz and michalwski, I have done some testing and found the following results: – Shubham1164 Nov 15 '18 at 04:00
  • 1. Inside mod_websockets, {ping_rate, x} attribute helps in the automatic server pings and hence it helps in preventing automatic log out after 60s on the mobile (react-native app) only but not on the chrome browser (using strophe.js with HTML). 2. Now I don't need to use mod_ping module for pining, this saves my bandwidth. 3. {timeout, 60000} attribute which must help in increasing the log out time on clients but it fails to do so, I think my client app is responsible for this 60s auto log out issue not the sever. – Shubham1164 Nov 15 '18 at 04:11
  • Ultimately, I am in better position than before now. Thanks michalwski. Thanks erszcz – Shubham1164 Nov 15 '18 at 04:12