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,
arrivalTime: now,
})
b.Unlock()
b.readCond.Broadcast()
b.Unlock()
return
}
b.calc(pkt, &rtpPacket, now, false)
b.Unlock()
b.readCond.Broadcast()
b.Unlock()
return
}
@@ -507,6 +507,7 @@ func (b *Buffer) Close() error {
b.RLock()
rtpStats := b.rtpStats
b.readCond.Broadcast()
b.RUnlock()
if rtpStats != nil {
@@ -520,7 +521,6 @@ func (b *Buffer) Close() error {
}
}
b.readCond.Broadcast()
if cb := b.getOnClose(); cb != nil {
cb()
}