mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-06 14:07:36 +03:00
Don't cancel transcoding session if context is canceled
This commit is contained in:
parent
fc8462dc8a
commit
05c6cdea1a
2 changed files with 5 additions and 39 deletions
|
@ -39,7 +39,7 @@ func (e *ffmpeg) ExtractImage(ctx context.Context, path string) (io.ReadCloser,
|
||||||
|
|
||||||
func (e *ffmpeg) start(ctx context.Context, args []string) (io.ReadCloser, error) {
|
func (e *ffmpeg) start(ctx context.Context, args []string) (io.ReadCloser, error) {
|
||||||
log.Trace(ctx, "Executing ffmpeg command", "cmd", args)
|
log.Trace(ctx, "Executing ffmpeg command", "cmd", args)
|
||||||
j := &Cmd{ctx: ctx, args: args}
|
j := &ffCmd{args: args}
|
||||||
j.PipeReader, j.out = io.Pipe()
|
j.PipeReader, j.out = io.Pipe()
|
||||||
err := j.start()
|
err := j.start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -49,16 +49,15 @@ func (e *ffmpeg) start(ctx context.Context, args []string) (io.ReadCloser, error
|
||||||
return j, nil
|
return j, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type Cmd struct {
|
type ffCmd struct {
|
||||||
*io.PipeReader
|
*io.PipeReader
|
||||||
out *io.PipeWriter
|
out *io.PipeWriter
|
||||||
ctx context.Context
|
|
||||||
args []string
|
args []string
|
||||||
cmd *exec.Cmd
|
cmd *exec.Cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *Cmd) start() error {
|
func (j *ffCmd) start() error {
|
||||||
cmd := exec.CommandContext(j.ctx, j.args[0], j.args[1:]...) // #nosec
|
cmd := exec.Command(j.args[0], j.args[1:]...) // #nosec
|
||||||
cmd.Stdout = j.out
|
cmd.Stdout = j.out
|
||||||
if log.CurrentLevel() >= log.LevelTrace {
|
if log.CurrentLevel() >= log.LevelTrace {
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
|
@ -73,7 +72,7 @@ func (j *Cmd) start() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *Cmd) wait() {
|
func (j *ffCmd) wait() {
|
||||||
if err := j.cmd.Wait(); err != nil {
|
if err := j.cmd.Wait(); err != nil {
|
||||||
var exitErr *exec.ExitError
|
var exitErr *exec.ExitError
|
||||||
if errors.As(err, &exitErr) {
|
if errors.As(err, &exitErr) {
|
||||||
|
@ -83,10 +82,6 @@ func (j *Cmd) wait() {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if j.ctx.Err() != nil {
|
|
||||||
_ = j.out.CloseWithError(j.ctx.Err())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
_ = j.out.Close()
|
_ = j.out.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
29
utils/cache/file_caches_test.go
vendored
29
utils/cache/file_caches_test.go
vendored
|
@ -120,31 +120,6 @@ var _ = Describe("File Caches", func() {
|
||||||
// TODO How to make the fscache reader return the underlying reader error?
|
// TODO How to make the fscache reader return the underlying reader error?
|
||||||
//Expect(err).To(MatchError("read failure"))
|
//Expect(err).To(MatchError("read failure"))
|
||||||
|
|
||||||
// Data should not be cached (or eventually be removed from cache)
|
|
||||||
Eventually(func() bool {
|
|
||||||
s, _ = fc.Get(context.Background(), &testArg{"test"})
|
|
||||||
if s != nil {
|
|
||||||
return s.Cached
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}).Should(BeFalse())
|
|
||||||
})
|
|
||||||
})
|
|
||||||
When("context is canceled", func() {
|
|
||||||
It("does not cache", func() {
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
|
||||||
fc := callNewFileCache("test", "1KB", "test", 0, func(ctx context.Context, arg Item) (io.Reader, error) {
|
|
||||||
return &ctxFakeReader{ctx}, nil
|
|
||||||
})
|
|
||||||
|
|
||||||
s, err := fc.Get(ctx, &testArg{"test"})
|
|
||||||
Expect(err).ToNot(HaveOccurred())
|
|
||||||
cancel()
|
|
||||||
b := make([]byte, 10)
|
|
||||||
_, err = s.Read(b)
|
|
||||||
// TODO Should be context.Canceled error
|
|
||||||
Expect(err).To(MatchError(io.EOF))
|
|
||||||
|
|
||||||
// Data should not be cached (or eventually be removed from cache)
|
// Data should not be cached (or eventually be removed from cache)
|
||||||
Eventually(func() bool {
|
Eventually(func() bool {
|
||||||
s, _ = fc.Get(context.Background(), &testArg{"test"})
|
s, _ = fc.Get(context.Background(), &testArg{"test"})
|
||||||
|
@ -166,7 +141,3 @@ func (t *testArg) Key() string { return t.s }
|
||||||
type errFakeReader struct{ err error }
|
type errFakeReader struct{ err error }
|
||||||
|
|
||||||
func (e errFakeReader) Read([]byte) (int, error) { return 0, e.err }
|
func (e errFakeReader) Read([]byte) (int, error) { return 0, e.err }
|
||||||
|
|
||||||
type ctxFakeReader struct{ ctx context.Context }
|
|
||||||
|
|
||||||
func (e *ctxFakeReader) Read([]byte) (int, error) { return 0, e.ctx.Err() }
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue