fix: noise protocol channel close race condition

This commit is contained in:
Prem Chaitanya Prathi 2023-08-04 17:19:53 +05:30
parent 42b2c0bc6d
commit 884f65ecdf
No known key found for this signature in database

View File

@ -95,6 +95,7 @@ func (r *NoiseWakuRelay) Subscribe(ctx context.Context, contentTopic string) <-c
for { for {
select { select {
case <-ctx.Done(): case <-ctx.Done():
close(sub.msgChan)
return return
case env := <-sub.broadcastSub.Ch: case env := <-sub.broadcastSub.Ch:
if env == nil { if env == nil {
@ -137,7 +138,6 @@ func (r *NoiseWakuRelay) Stop() {
for _, contentTopicSubscriptions := range r.subscriptionChPerContentTopic { for _, contentTopicSubscriptions := range r.subscriptionChPerContentTopic {
for _, c := range contentTopicSubscriptions { for _, c := range contentTopicSubscriptions {
c.broadcastSub.Unsubscribe() c.broadcastSub.Unsubscribe()
close(c.msgChan)
} }
} }
} }