Set timeout for client disconnection
This commit is contained in:
parent
a69606e9aa
commit
dabbe5c305
@ -98,9 +98,24 @@ func (s *Stream) handleBroadcaster(c *rtmp.Conn, nc net.Conn) {
|
|||||||
// Ensure cleanup
|
// Ensure cleanup
|
||||||
defer func() {
|
defer func() {
|
||||||
// Ensure all clients have been removed
|
// Ensure all clients have been removed
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
for len(s.Clients) > 0 {
|
for len(s.Clients) > 0 {
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
// Timed out while waiting for clients to disconnect, log and remove stream.
|
||||||
|
s.server.RemoveStream(s)
|
||||||
|
s.server.Logger.Errorw("Timeout while waiting for clients to disconnect from stream.",
|
||||||
|
"stream_name", s.Name,
|
||||||
|
"stream_duration", time.Since(s.startTime),
|
||||||
|
"bytes_received", humanize.Bytes(s.bytesReceived.Load()))
|
||||||
|
return
|
||||||
|
default:
|
||||||
time.Sleep(200 * time.Millisecond)
|
time.Sleep(200 * time.Millisecond)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Once all clients have been removed, remove stream from server
|
// Once all clients have been removed, remove stream from server
|
||||||
s.server.RemoveStream(s)
|
s.server.RemoveStream(s)
|
||||||
s.server.Logger.Infow("Stream has been successfully stopped.",
|
s.server.Logger.Infow("Stream has been successfully stopped.",
|
||||||
|
@ -2,7 +2,7 @@ package dogtamer
|
|||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
const Version string = "v0.1.6"
|
const Version string = "v0.1.7"
|
||||||
|
|
||||||
var Build string
|
var Build string
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user