Compare commits

...

4 Commits

Author SHA1 Message Date
Alex X
699a995e8c Fix deadlock on write to track channel 2025-04-08 11:33:04 +03:00
Alex X
ce02b03a73 Merge pull request #1682 from infastin/fix/sender-deadlock
fix(core): potential sender goroutine deadlock
2025-04-08 11:26:18 +03:00
infastin
487527f5a5 chore: remove mutexes 2025-04-05 13:50:02 +05:00
infastin
0669cfbebf fix(core): potential sender loop deadlock 2025-03-31 19:12:07 +05:00

View File

@@ -97,13 +97,17 @@ func NewSender(media *Media, codec *Codec) *Sender {
buf: buf, buf: buf,
} }
s.Input = func(packet *Packet) { s.Input = func(packet *Packet) {
// writing to nil chan - OK, writing to closed chan - panic
s.mu.Lock() s.mu.Lock()
select { if s.buf != nil {
case s.buf <- packet: // unblocked write to channel
s.Bytes += len(packet.Payload) select {
s.Packets++ case s.buf <- packet:
default: s.Bytes += len(packet.Payload)
s.Packets++
default:
s.Drops++
}
} else {
s.Drops++ s.Drops++
} }
s.mu.Unlock() s.mu.Unlock()
@@ -139,13 +143,13 @@ 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() {