Skip to content

Commit

Permalink
Recover from panic while RunSegmentation
Browse files Browse the repository at this point in the history
  • Loading branch information
leszko committed Jan 8, 2025
1 parent 17832e7 commit 8d145f5
Showing 1 changed file with 12 additions and 0 deletions.
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 @@ import (
"bufio"
"context"
"encoding/base32"
"errors"
"fmt"
"io"
"log/slog"
Expand Down Expand Up @@ -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)
}()
Expand Down Expand Up @@ -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)
}
}

0 comments on commit 8d145f5

Please sign in to comment.