backup: prevent hang using --stdin-from-command if upload fails (#21829)

This commit is contained in:
Michael Eischer
2026-05-31 15:27:05 +02:00
committed by GitHub
parent 451cc6c048
commit ce24640d75
3 changed files with 24 additions and 0 deletions
+12
View File
@@ -6,6 +6,7 @@ import (
"io"
"strings"
"testing"
"time"
"github.com/restic/restic/internal/fs"
"github.com/restic/restic/internal/test"
@@ -51,3 +52,14 @@ func TestCommandReaderOutput(t *testing.T) {
test.Equals(t, "hello world", strings.TrimSpace(buf.String()))
}
func TestCommandReaderQuickClose(t *testing.T) {
ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second)
defer cancel()
reader, err := fs.NewCommandReader(ctx, []string{"sleep", "3600"}, func(msg string, args ...interface{}) {})
test.OK(t, err)
// test that close returns before the context expires
_ = reader.Close()
test.OK(t, ctx.Err())
}