Skip to content

Commit

Permalink
fix race condition on ticker ping.
Browse files Browse the repository at this point in the history
fixes nevent1qqszqakrmmjyjelgp06f3hx0fu70xyvmqt4ed8v65xpmpy9g8nj9qgqpz4mhxue69uhkummnw3ezummcw3ezuer9wchsz9nhwden5te0dehhxarjv4kxjar9wvhx7un89uq32amnwvaz7tmjv4kxz7fwv3sk6atn9e5k7tcnynjra
  • Loading branch information
fiatjaf committed Nov 24, 2024
1 parent 72c7892 commit 98d3766
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,13 @@ func (r *Relay) ConnectWithTLS(ctx context.Context, tlsConfig *tls.Config) error
for {
select {
case <-ticker.C:
err := wsutil.WriteClientMessage(r.Connection.conn, ws.OpPing, nil)
if err != nil {
InfoLogger.Printf("{%s} error writing ping: %v; closing websocket", r.URL, err)
r.Close() // this should trigger a context cancelation
return
if r.Connection != nil {
err := wsutil.WriteClientMessage(r.Connection.conn, ws.OpPing, nil)
if err != nil {
InfoLogger.Printf("{%s} error writing ping: %v; closing websocket", r.URL, err)
r.Close() // this should trigger a context cancelation
return
}
}
case writeRequest := <-r.writeQueue:
// all write requests will go through this to prevent races
Expand Down

0 comments on commit 98d3766

Please sign in to comment.