fix: 关闭正在推流的sink, 发生crash问题.

This commit is contained in:
ydajiang
2025-04-21 17:44:11 +08:00
parent cc86e94c5a
commit 02a0a42238

View File

@@ -274,17 +274,19 @@ func (s *BaseSink) Close() {
s.Lock()
defer func() {
closed := s.State == SessionStateClosed
s.State = SessionStateClosed
s.UnLock()
// 最后断开网络连接, 确保从source删除sink之前, 推流是安全的.
if s.Conn != nil {
s.Conn.Close()
s.Conn = nil
}
if !closed {
if s.cancelCtx != nil {
s.cancelFunc()
}
if s.cancelCtx != nil {
s.cancelFunc()
// 最后断开网络连接, 确保从source删除sink之前, 推流是安全的.
if s.Conn != nil {
s.Conn.Close()
}
}
}()