fix(core): potential sender loop deadlock

This commit is contained in:
infastin
2025-03-31 19:12:07 +05:00
parent d99bf122ea
commit 0669cfbebf
+12 -5
View File
@@ -139,22 +139,29 @@ func (s *Sender) Start() {
} }
s.done = make(chan struct{}) s.done = make(chan struct{})
go func() { // pass buf directly so that it's impossible for buf to be nil
// for range on nil chan is OK go func(buf chan *Packet) {
for packet := range s.buf { for packet := range buf {
s.Output(packet) s.Output(packet)
} }
close(s.done) close(s.done)
}() }(s.buf)
} }
func (s *Sender) Wait() { func (s *Sender) Wait() {
if done := s.done; done != nil { s.mu.Lock()
done := s.done
s.mu.Unlock()
if done != nil {
<-done <-done
} }
} }
func (s *Sender) State() string { func (s *Sender) State() string {
s.mu.Lock()
defer s.mu.Unlock()
if s.buf == nil { if s.buf == nil {
return "closed" return "closed"
} }