From 8d145f565036d2f24dd090b0c714046098ef76b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Leszko?= Date: Wed, 8 Jan 2025 10:09:15 +0100 Subject: [PATCH 1/2] Recover from panic while RunSegmentation --- media/rtmp2segment.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/media/rtmp2segment.go b/media/rtmp2segment.go index db1d5a8eb..9b78a85b1 100644 --- a/media/rtmp2segment.go +++ b/media/rtmp2segment.go @@ -6,6 +6,7 @@ import ( "bufio" "context" "encoding/base32" + "errors" "fmt" "io" "log/slog" @@ -35,6 +36,7 @@ func (ms *MediaSegmenter) RunSegmentation(ctx context.Context, in string, segmen wg := &sync.WaitGroup{} wg.Add(1) go func() { + defer recoverFromPanic() defer wg.Done() processSegments(ctx, segmentHandler, outFilePattern, completionSignal) }() @@ -254,3 +256,13 @@ func randomString() string { } return strings.TrimRight(base32.StdEncoding.EncodeToString(b), "=") } + +func recoverFromPanic() { + if r := recover(); r != nil { + err, ok := r.(error) + if !ok { + err = errors.New("unrecoverable error") + } + clog.Errorf(context.Background(), "RunSegmentation failed with panic err=%v", err) + } +} From 881891304348dc25abe4694d6b56a99c4358f96a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Leszko?= Date: Wed, 8 Jan 2025 10:27:50 +0100 Subject: [PATCH 2/2] Fix order --- media/rtmp2segment.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/media/rtmp2segment.go b/media/rtmp2segment.go index 9b78a85b1..7a0edca88 100644 --- a/media/rtmp2segment.go +++ b/media/rtmp2segment.go @@ -36,8 +36,8 @@ func (ms *MediaSegmenter) RunSegmentation(ctx context.Context, in string, segmen wg := &sync.WaitGroup{} wg.Add(1) go func() { - defer recoverFromPanic() defer wg.Done() + defer recoverFromPanic() processSegments(ctx, segmentHandler, outFilePattern, completionSignal) }()