guard ping writes with the mutex.

fixes https://github.com/nbd-wtf/go-nostr/issues/76#issuecomment-1521170395
This commit is contained in:
fiatjaf 2023-04-26 08:04:47 -03:00
parent b077a41f83
commit 3838ed7e91
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1

View File

@ -119,7 +119,9 @@ func (r *Relay) Connect(ctx context.Context) error {
for {
select {
case <-ticker.C:
conn.mutex.Lock()
err := conn.socket.WriteMessage(websocket.PingMessage, nil)
conn.mutex.Unlock()
if err != nil {
InfoLogger.Printf("{%s} error writing ping: %v; closing websocket", r.URL, err)
return