Avoid potential deadlock

This commit is contained in:
Zoltán Papp
2025-06-02 16:55:33 +02:00
parent fbdccbc2a1
commit 2a3623d6ac
+3 -6
View File
@@ -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{}{}
}()
}
}