diff options
author | Wim <wim@42.be> | 2023-08-05 20:43:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-05 20:43:19 +0200 |
commit | 56e7bd01ca09ad52b0c4f48f146a20a4f1b78696 (patch) | |
tree | b1355645342667209263cbd355dc0b4254f1e8fe /vendor/go.mau.fi/whatsmeow/keepalive.go | |
parent | 9459495484d6e06a3d46de64fccd8d06f7ccc72c (diff) | |
download | matterbridge-msglm-56e7bd01ca09ad52b0c4f48f146a20a4f1b78696.tar.gz matterbridge-msglm-56e7bd01ca09ad52b0c4f48f146a20a4f1b78696.tar.bz2 matterbridge-msglm-56e7bd01ca09ad52b0c4f48f146a20a4f1b78696.zip |
Diffstat (limited to 'vendor/go.mau.fi/whatsmeow/keepalive.go')
-rw-r--r-- | vendor/go.mau.fi/whatsmeow/keepalive.go | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/vendor/go.mau.fi/whatsmeow/keepalive.go b/vendor/go.mau.fi/whatsmeow/keepalive.go index d5e40286..48510a12 100644 --- a/vendor/go.mau.fi/whatsmeow/keepalive.go +++ b/vendor/go.mau.fi/whatsmeow/keepalive.go @@ -23,10 +23,13 @@ var ( KeepAliveIntervalMin = 20 * time.Second // KeepAliveIntervalMax specifies the maximum interval for websocket keepalive pings. KeepAliveIntervalMax = 30 * time.Second + + // KeepAliveMaxFailTime specifies the maximum time to wait before forcing a reconnect if keepalives fail repeatedly. + KeepAliveMaxFailTime = 3 * time.Minute ) func (cli *Client) keepAliveLoop(ctx context.Context) { - var lastSuccess time.Time + lastSuccess := time.Now() var errorCount int for { interval := rand.Int63n(KeepAliveIntervalMax.Milliseconds()-KeepAliveIntervalMin.Milliseconds()) + KeepAliveIntervalMin.Milliseconds() @@ -41,6 +44,11 @@ func (cli *Client) keepAliveLoop(ctx context.Context) { ErrorCount: errorCount, LastSuccess: lastSuccess, }) + if cli.EnableAutoReconnect && time.Since(lastSuccess) > KeepAliveMaxFailTime { + cli.Log.Debugf("Forcing reconnect due to keepalive failure") + cli.Disconnect() + go cli.autoReconnect() + } } else { if errorCount > 0 { errorCount = 0 |