fix(core): potential sender loop deadlock

This commit is contained in:
infastin
2025-03-31 19:12:07 +05:00
parent d99bf122ea
commit 0669cfbebf

View File

@@ -139,22 +139,29 @@ func (s *Sender) Start() {
}
s.done = make(chan struct{})
go func() {
// for range on nil chan is OK
for packet := range s.buf {
// pass buf directly so that it's impossible for buf to be nil
go func(buf chan *Packet) {
for packet := range buf {
s.Output(packet)
}
close(s.done)
}()
}(s.buf)
}
func (s *Sender) Wait() {
if done := s.done; done != nil {
s.mu.Lock()
done := s.done
s.mu.Unlock()
if done != nil {
<-done
}
}
func (s *Sender) State() string {
s.mu.Lock()
defer s.mu.Unlock()
if s.buf == nil {
return "closed"
}