From 2a3623d6ac9b0d83a7012daac632310bd66dfed7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Papp?= Date: Mon, 2 Jun 2025 16:55:33 +0200 Subject: [PATCH] Avoid potential deadlock --- client/internal/peer/status.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/client/internal/peer/status.go b/client/internal/peer/status.go index abb2aa7b9..d3375f107 100644 --- a/client/internal/peer/status.go +++ b/client/internal/peer/status.go @@ -164,10 +164,6 @@ func (s *StatusChangeSubscription) Events() chan struct{} { return s.eventsChan } -func (s *StatusChangeSubscription) close() { - close(s.eventsChan) -} - // Status holds a state of peers, signal, management connections and relays type Status struct { mux sync.Mutex @@ -604,7 +600,6 @@ func (d *Status) UnsubscribePeerStateChanges(subscription *StatusChangeSubscript return } - sub.close() delete(channels, subscription.id) if len(channels) == 0 { delete(d.changeNotify, sub.peerID) @@ -990,7 +985,9 @@ func (d *Status) notifyPeerStateChangeListeners(peerID string) { for _, sub := range subs { // block the write because we do not want to miss notification // must have to be sure we will run the GetPeerState() on separated thread - sub.eventsChan <- struct{}{} + go func() { + sub.eventsChan <- struct{}{} + }() } }