restreamer icon indicating copy to clipboard operation
restreamer copied to clipboard

Panic due to double channel close in Streamer.Stream()

Open onitake opened this issue 2 years ago • 0 comments

In Streamer.Stream(), there is an inherent concurrency issue, because the Connection.Closed flag is used to determine if the Connection.Queue channel needs to be closed or not: https://github.com/onitake/restreamer/blob/6a701cadf949030788c0d29b3952ac40da487053/streaming/streamer.go#L334-L336

If someone closes the channel, the flag update is delayed, and a concurrent goroutine may try to close it again: https://github.com/onitake/restreamer/blob/6a701cadf949030788c0d29b3952ac40da487053/streaming/connection.go#L132

As quick&dirty workaround, recover() can be used, but it would be better to remove this flag and find a different way to signal closure and trigger cleanup.

onitake avatar Jul 21 '23 14:07 onitake