do not close relay connection when ping fails because some relays just do not pong.

This commit is contained in:
fiatjaf
2025-01-25 00:26:36 -03:00
parent 6daecc8bd2
commit 17431dee59

View File

@@ -9,6 +9,7 @@ import (
"log" "log"
"net/http" "net/http"
"strconv" "strconv"
"strings"
"sync" "sync"
"sync/atomic" "sync/atomic"
"time" "time"
@@ -187,7 +188,7 @@ func (r *Relay) ConnectWithTLS(ctx context.Context, tlsConfig *tls.Config) error
case <-ticker.C: case <-ticker.C:
if r.Connection != nil { if r.Connection != nil {
err := r.Connection.Ping(r.connectionContext) err := r.Connection.Ping(r.connectionContext)
if err != nil { if err != nil && !strings.Contains(err.Error(), "failed to wait for pong") {
InfoLogger.Printf("{%s} error writing ping: %v; closing websocket", r.URL, err) InfoLogger.Printf("{%s} error writing ping: %v; closing websocket", r.URL, err)
r.Close() // this should trigger a context cancelation r.Close() // this should trigger a context cancelation
return return