mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-07-07 14:49:56 +02:00
fix race condition on ticker ping.
fixes nevent1qqszqakrmmjyjelgp06f3hx0fu70xyvmqt4ed8v65xpmpy9g8nj9qgqpz4mhxue69uhkummnw3ezummcw3ezuer9wchsz9nhwden5te0dehhxarjv4kxjar9wvhx7un89uq32amnwvaz7tmjv4kxz7fwv3sk6atn9e5k7tcnynjra
This commit is contained in:
2
relay.go
2
relay.go
@ -182,12 +182,14 @@ func (r *Relay) ConnectWithTLS(ctx context.Context, tlsConfig *tls.Config) error
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
|
if r.Connection != nil {
|
||||||
err := wsutil.WriteClientMessage(r.Connection.conn, ws.OpPing, nil)
|
err := wsutil.WriteClientMessage(r.Connection.conn, ws.OpPing, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
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
|
||||||
}
|
}
|
||||||
|
}
|
||||||
case writeRequest := <-r.writeQueue:
|
case writeRequest := <-r.writeQueue:
|
||||||
// all write requests will go through this to prevent races
|
// all write requests will go through this to prevent races
|
||||||
debugLogf("{%s} sending %v\n", r.URL, string(writeRequest.msg))
|
debugLogf("{%s} sending %v\n", r.URL, string(writeRequest.msg))
|
||||||
|
Reference in New Issue
Block a user