Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recover from panic while RunSegmentation #3342

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions media/rtmp2segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"bufio"
"context"
"encoding/base32"
"errors"
"fmt"
"io"
"log/slog"
Expand Down Expand Up @@ -36,6 +37,7 @@
wg.Add(1)
go func() {
defer wg.Done()
defer recoverFromPanic()

Check warning on line 40 in media/rtmp2segment.go

View check run for this annotation

Codecov / codecov/patch

media/rtmp2segment.go#L40

Added line #L40 was not covered by tests
processSegments(ctx, segmentHandler, outFilePattern, completionSignal)
}()

Expand Down Expand Up @@ -254,3 +256,13 @@
}
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)

Check warning on line 266 in media/rtmp2segment.go

View check run for this annotation

Codecov / codecov/patch

media/rtmp2segment.go#L260-L266

Added lines #L260 - L266 were not covered by tests
}
}
Loading