fix: prevent `panic: send on closed channel`
This commit is contained in:
parent
5aed0d178f
commit
bafb0a71d0
|
@ -82,7 +82,8 @@ type MessageSender struct {
|
|||
ephemeralKeysMutex sync.Mutex
|
||||
|
||||
// messageEventsSubscriptions contains all the subscriptions for message events
|
||||
messageEventsSubscriptions []chan<- *MessageEvent
|
||||
messageEventsSubscriptions []chan<- *MessageEvent
|
||||
messageEventsSubscriptionsMutex sync.Mutex
|
||||
|
||||
featureFlags FeatureFlags
|
||||
|
||||
|
@ -114,6 +115,9 @@ func NewMessageSender(
|
|||
}
|
||||
|
||||
func (s *MessageSender) Stop() {
|
||||
s.messageEventsSubscriptionsMutex.Lock()
|
||||
defer s.messageEventsSubscriptionsMutex.Unlock()
|
||||
|
||||
for _, c := range s.messageEventsSubscriptions {
|
||||
close(c)
|
||||
}
|
||||
|
@ -1184,6 +1188,10 @@ func (s *MessageSender) notifyOnSentMessage(sentMessage *SentMessage) {
|
|||
Type: MessageSent,
|
||||
SentMessage: sentMessage,
|
||||
}
|
||||
|
||||
s.messageEventsSubscriptionsMutex.Lock()
|
||||
defer s.messageEventsSubscriptionsMutex.Unlock()
|
||||
|
||||
// Publish on channels, drop if buffer is full
|
||||
for _, c := range s.messageEventsSubscriptions {
|
||||
select {
|
||||
|
@ -1202,6 +1210,9 @@ func (s *MessageSender) notifyOnScheduledMessage(recipient *ecdsa.PublicKey, mes
|
|||
RawMessage: message,
|
||||
}
|
||||
|
||||
s.messageEventsSubscriptionsMutex.Lock()
|
||||
defer s.messageEventsSubscriptionsMutex.Unlock()
|
||||
|
||||
// Publish on channels, drop if buffer is full
|
||||
for _, c := range s.messageEventsSubscriptions {
|
||||
select {
|
||||
|
|
Loading…
Reference in New Issue