go-xmpp icon indicating copy to clipboard operation
go-xmpp copied to clipboard

Is there a way to check if connection is still alive?

Open mdosch opened this issue 6 years ago • 8 comments

First thank you for this library and the echo bot example. I was able to build a simple bot without programming experience following the example, although I have to admit at the start I used code from this repo.

But despite reading in the library a lot it is still not clear to me how I could check whether the connection is still alive. My bot works pretty well till it stops working due to a network flaw/reconnect. Could you please give me a hint at which modules/functions I should have a closer look?

mdosch avatar Apr 08 '18 08:04 mdosch

Client-to-Server Pings may help you.

https://xmpp.org/extensions/xep-0199.html#c2s

shrhdk avatar Apr 09 '18 22:04 shrhdk

thx, I'll try to implement a ping if there was no activity since ~5 minutes.

mdosch avatar Apr 12 '18 14:04 mdosch

Ping is a bit heavy on the server. Some servers (like ejabberd on SaaS) support whitespace ping. I will try to add this method (whitespace ping) when I have some time to work on go-xmpp.

mremond avatar Jan 21 '19 15:01 mremond

@mdosch Sorry it took so long, but I am finally working on the disconnect detection and adding some way to trigger reconnect.

mremond avatar Jun 05 '19 15:06 mremond

@mdosch I think the new ClientManager should do what you need. It reconnects automatically when the connection is lost. You can check how to use it in the xmpp_echo example: https://github.com/FluuxIO/go-xmpp/blob/master/cmd/xmpp_echo/xmpp_echo.go

I guess we can close this ticket now. You can also monitor progress on connection loss detection that will add an active way to detect connection loss: #35

mremond avatar Jun 06 '19 10:06 mremond

Thank you, I will check it out. :)

mdosch avatar Jun 07 '19 14:06 mdosch

Although I am using the StreamManager as in your echo bot example, see here it seems to still not work properly. Whenever I restart my prosody the bot seems to not reconnect as it doesn't reply anymore. Do I need to configure more than shown in the echo bot example?

mdosch avatar May 16 '20 11:05 mdosch

This is the output from one of my bots in journalctl:

Jul 04 12:39:23 v220191283267104968 gowttr[26540]: 2020/07/04 12:39:23 unknown namespace urn:ietf:params:xml:ns:xmpp-streams <not-well-formed/>                                                                                               
Jul 04 12:39:38 v220191283267104968 gowttr[26540]: 2020/07/04 12:39:38 NextStart read tcp 127.0.0.1:39290->127.0.0.1:5222: use of closed network connection                                                                                   
Jul 04 12:39:53 v220191283267104968 gowttr[26540]: 2020/07/04 12:39:53 NextStart read tcp 127.0.0.1:39324->127.0.0.1:5222: read: connection reset by peer                                                                                     
Jul 04 12:39:53 v220191283267104968 gowttr[26540]: 2020/07/04 12:39:53 unknown namespace urn:ietf:params:xml:ns:xmpp-streams <not-well-formed/>                                                                                               
Jul 04 12:40:08 v220191283267104968 gowttr[26540]: 2020/07/04 12:40:08 stream error: system-shutdown
Jul 04 12:40:08 v220191283267104968 gowttr[26540]: 2020/07/04 12:40:08 unknown namespace urn:ietf:params:xml:ns:xmpp-streams <not-well-formed/>                                                                                               
Jul 04 12:40:08 v220191283267104968 gowttr[26540]: 2020/07/04 12:40:08 NextStart read tcp 127.0.0.1:39414->127.0.0.1:5222: use of closed network connection                                                                                   
Jul 04 12:40:23 v220191283267104968 gowttr[26540]: 2020/07/04 12:40:23 unknown namespace urn:ietf:params:xml:ns:xmpp-streams <not-well-formed/>
Jul 04 12:40:23 v220191283267104968 gowttr[26540]: 2020/07/04 12:40:23 NextStart read tcp 127.0.0.1:39516->127.0.0.1:5222: use of closed network connection
Jul 04 12:40:23 v220191283267104968 gowttr[26540]: 2020/07/04 12:40:23 NextStart read tcp 127.0.0.1:39520->127.0.0.1:5222: use of closed network connection
Jul 04 12:40:23 v220191283267104968 gowttr[26540]: 2020/07/04 12:40:23 unknown namespace urn:ietf:params:xml:ns:xmpp-streams <not-well-formed/>

mdosch avatar Jul 04 '20 10:07 mdosch