Call Broadcast in lock scope. (#3625)

* Call Broadcast in lock scope.

Seems like there is a possible window where things can hang forever
if a goroutine enters the Wait) after the lock is released but before
Broadcast gets called, it will never see that broadcast and will hang forever.

* RLock
This commit is contained in:
Raja Subramanian
2025-04-25 12:12:10 +05:30
committed by GitHub
parent b760918a0d
commit f24152b4c0
+3 -3
View File
@@ -397,14 +397,14 @@ func (b *Buffer) Write(pkt []byte) (n int, err error) {
packet: packet, packet: packet,
arrivalTime: now, arrivalTime: now,
}) })
b.Unlock()
b.readCond.Broadcast() b.readCond.Broadcast()
b.Unlock()
return return
} }
b.calc(pkt, &rtpPacket, now, false) b.calc(pkt, &rtpPacket, now, false)
b.Unlock()
b.readCond.Broadcast() b.readCond.Broadcast()
b.Unlock()
return return
} }
@@ -507,6 +507,7 @@ func (b *Buffer) Close() error {
b.RLock() b.RLock()
rtpStats := b.rtpStats rtpStats := b.rtpStats
b.readCond.Broadcast()
b.RUnlock() b.RUnlock()
if rtpStats != nil { if rtpStats != nil {
@@ -520,7 +521,6 @@ func (b *Buffer) Close() error {
} }
} }
b.readCond.Broadcast()
if cb := b.getOnClose(); cb != nil { if cb := b.getOnClose(); cb != nil {
cb() cb()
} }