42wim / matterbridge

bridge between mattermost, IRC, gitter, xmpp, slack, discord, telegram, rocketchat, twitch, ssh-chat, zulip, whatsapp, keybase, matrix, microsoft teams, nextcloud, mumble, vk and more with REST API (mattermost not required!)
Apache License 2.0
6.59k stars 613 forks source link

Reconnecting to WhatsApp fails #1091

Closed wryun closed 4 years ago

wryun commented 4 years ago

Describe the bug Connection to WhatsApp drops, and reconnect fails in similar ways until I restart entirely.

To Reproduce Run the bridge for a long time. This may be due to a dodgy connection (I'm running the bridge on the same phone as whatsapp in termux since I didn't want to bother with a VM); it could be on wifi drop/reconnect.

Expected behavior Reconnecting should work.

Screenshots/debug logs Sorry, no debug logs yet. Will get soon.

[2020-04-16T23:31:31Z] ERROR whatsapp:     Connection failed, underlying error: connection to WhatsApp servers failed: read tcp 192.168.20.12:40199->157.240.8.53:443: read: connection timed out
[2020-04-16T23:31:31Z]  INFO whatsapp:     Waiting 5.347314976s...
[2020-04-16T23:31:36Z]  INFO whatsapp:     Reconnecting...
[2020-04-16T23:31:37Z] ERROR whatsapp:     Connection failed, underlying error: connection to WhatsApp servers failed: read tcp 192.168.20.12:40199->157.240.8.53:443: read: connection timed out
[2020-04-16T23:31:37Z]  INFO whatsapp:     Waiting 2.823465695s...
[2020-04-16T23:31:39Z]  INFO whatsapp:     Reconnecting...
[2020-04-16T23:31:40Z] ERROR whatsapp:     Connection failed, underlying error: connection to WhatsApp servers failed: read tcp 192.168.20.12:40199->157.240.8.53:443: read: connection timed out
[2020-04-16T23:31:40Z]  INFO whatsapp:     Waiting 25.543962211s...
[2020-04-16T23:32:05Z]  INFO whatsapp:     Reconnecting...
[2020-04-16T23:32:05Z] ERROR whatsapp:     Connection failed, underlying error: connection to WhatsApp servers failed: read tcp 192.168.20.12:40199->157.240.8.53:443: read: connection timed out
[2020-04-16T23:32:05Z]  INFO whatsapp:     Waiting 40.051916178s...
[2020-04-16T23:32:45Z]  INFO whatsapp:     Reconnecting...
[2020-04-16T23:32:46Z] ERROR whatsapp:     Connection failed, underlying error: connection to WhatsApp servers failed: read tcp 192.168.20.12:40199->157.240.8.53:443: read: connection timed out
[2020-04-16T23:32:46Z]  INFO whatsapp:     Waiting 2m2.466199038s...
[2020-04-16T23:34:48Z]  INFO whatsapp:     Reconnecting...
[2020-04-16T23:34:48Z] ERROR whatsapp:     Connection failed, underlying error: connection to WhatsApp servers failed: read tcp 192.168.20.12:40199->157.240.8.53:443: read: connection timed out
[2020-04-16T23:34:48Z]  INFO whatsapp:     Waiting 42.859659648s...
[2020-04-16T23:35:31Z]  INFO whatsapp:     Reconnecting...
[2020-04-16T23:35:31Z] ERROR whatsapp:     Connection failed, underlying error: connection to WhatsApp servers failed: read tcp 192.168.20.12:40199->157.240.8.53:443: read: connection timed out
[2020-04-16T23:35:31Z]  INFO whatsapp:     Waiting 5m0s...
[2020-04-16T23:40:31Z]  INFO whatsapp:     Reconnecting...
[2020-04-16T23:40:32Z] ERROR whatsapp:     Connection failed, underlying error: connection to WhatsApp servers failed: read tcp 192.168.20.12:40199->157.240.8.53:443: read: connection timed out
[2020-04-16T23:40:32Z]  INFO whatsapp:     Waiting 5m0s...
[2020-04-16T23:41:19Z]  INFO zulip:        got a bad event queue id error, reconnecting
[2020-04-16T23:45:32Z]  INFO whatsapp:     Reconnecting...
[2020-04-16T23:45:32Z] ERROR whatsapp:     Connection failed, underlying error: connection to WhatsApp servers failed: read tcp 192.168.20.12:40199->157.240.8.53:443: read: connection timed out
[2020-04-16T23:45:32Z]  INFO whatsapp:     Waiting 5m0s...

Environment (please complete the following information):

Additional context

[discord.---]
Token="..." 
Server="..." 
RemoteNickFormat="[{PROTOCOL}] {NICK} "
WebHookURL="..." 

[zulip.---]
Token="..." 
Login="bridge-bot@zulipchat.com"
Server="https://---.zulipchat.com"
RemoteNickFormat="[{PROTOCOL}] <{NICK}> "

[whatsapp.---]
Label="---"
Number="---" 
SessionFile="whatsapp----.gob"
QrOnWhiteTerminal=false
RemoteNickFormat="@{NICK}: "

[[gateway]]
name="gateway1"
enable=true

[[gateway.inout]]
account="discord.---"
channel="whatsapp"

[[gateway.inout]]
account="zulip.---"
channel="discord-whatsapp/topic:bridge"

[[gateway.inout]]
account="whatsapp.---"
channel="..." 
wryun commented 4 years ago

Confusingly, this is now not happening. Feel free to close. I'm still see regular connection drops, but reconnection usually succeeds. But I think these disconnections are simply to do with the network connection on the phone, since it's happening to discord as well. Exactly every 30 minutes.

One confusing thing I would note is that in this 'reconnection' situation there's never a success message (from any of the 3 bridges - only a notification that they're reconnecting).

42wim commented 4 years ago

The connection time out means it couldn't reach the destination, this is a network issue. I'm going to close this.

Cool that you run it on android though :-) 👍

wryun commented 4 years ago

I mean, I'm not entirely convinced it was a 'normal' connection issue, because discord/zulip weren't spitting errors (like they do on an ordinary connection drop), I would be surprised if whatsapp was down for > 15 minutes, and when I stopped and restarted it connected immediately. Perhaps it's not respecting the DNS TTL or something? But yes, without more evidence I agree this bug report is pretty useless, sorry.

wryun commented 4 years ago

Happened again today. Capped retries at 5 minutes and never managed to reconnect in over an hour.

Reconnected immediately as soon as I stopped and restarted process. Neither discord nor zulip were affected.

wryun commented 4 years ago

Turned on debug logs, but nothing useful added. WhatsApp just seems extremely unreliable at reconnecting. What seems to happen is that it thinks it needs to reconnect, but it's actually still connected. You can see this in odd sequence like:

[13147]  INFO whatsapp:     Waiting 5m0s...
[13447]  INFO whatsapp:     Reconnecting...
[13447] ERROR whatsapp:     Connection failed, underlying error: connection to WhatsApp servers failed: read tcp 192.168.20.12:42855->157.240.8.53:443: r
ead: connection timed out
[13447]  INFO whatsapp:     Waiting 5m0s...
[13597] ERROR whatsapp:     Connection failed, underlying error: connection to WhatsApp servers failed: read tcp 192.168.20.12:42875->157.240.8.53:443: r
ead: connection timed out
[13597]  INFO whatsapp:     Waiting 1s...
[13598]  INFO whatsapp:     Reconnecting...
[13598] ERROR whatsapp:     Connection failed, underlying error: connection to WhatsApp servers failed: read tcp 192.168.20.12:42875->157.240.8.53:443: read: connection timed out
[13598]  INFO whatsapp:     Waiting 1.033250665s...
[13599]  INFO whatsapp:     Reconnecting...
[13599] ERROR whatsapp:     Connection failed, underlying error: connection to WhatsApp servers failed: read tcp 192.168.20.12:42875->157.240.8.53:443: read: connection timed out
[13599]  INFO whatsapp:     Waiting 2.770223304s...
[13601]  INFO whatsapp:     Reconnecting...
[13604] ERROR whatsapp:     error processing data: error decoding binary: could not decode binary: invalid string with tag 174
[13747]  INFO whatsapp:     Reconnecting...
[13747] ERROR whatsapp:     Connection failed, underlying error: connection to WhatsApp servers failed: read tcp 192.168.20.12:42855->157.240.8.53:443: read: connection timed out
[13747]  INFO whatsapp:     Waiting 5m0s...
[14047]  INFO whatsapp:     Reconnecting...
[14047] ERROR whatsapp:     Connection failed, underlying error: connection to WhatsApp servers failed: read tcp 192.168.20.12:42855->157.240.8.53:443: read: connection timed out
[14047]  INFO whatsapp:     Waiting 5m0s...
[14347]  INFO whatsapp:     Reconnecting...
[14347] ERROR whatsapp:     Connection failed, underlying error: connection to WhatsApp servers failed: read tcp 192.168.20.12:42855->157.240.8.53:443: read: connection timed out

Where it seems like it's on a 5 minute back-off, but suddenly jumps in a says 1 sec reconnecting (and then still keeps printing messages about 5 minute back-off). I've also received messages while it looks like it's disconnected - although sometimes messages are missed (?).

wryun commented 4 years ago

(you can get a rought sense of the timing because of the numbering - I've excluded Zulip's regular heartbeat message)

JEK58 commented 3 years ago

I've got the same error. As soon as I restart the Matterbridge service / docker container it works again. Did you find out what the problem was?