From 22dfc1e265ceb10dc481e8ec09da738788f4d01a Mon Sep 17 00:00:00 2001 From: Marco Molteni <marco.molteni@mailbox.org> Date: Thu, 22 Apr 2021 15:30:52 +0200 Subject: [PATCH] execext.RunCommand: fix: do not pass a cancellable context to mvdan.cc/sh We used to pass to mvdan.cc/sh/interp.Runner a context that was cancelled on reception of a OS signal. This caused the Runner to terminate the subprocess abruptly. The correct behavior instead is for us to completely ignore the signal and let the subprocess deal with it. If the subprocess doesn't handle the signal, it will be terminated. If the subprocess does handle the signal, it knows better than us wether it wants to cleanup and terminate or do something different. So now we pass an empty context just to make the API of interp.Runner happy Fixes go-task/task/#458 --- internal/execext/exec.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/internal/execext/exec.go b/internal/execext/exec.go index cfdb578c..5b84cb91 100644 --- a/internal/execext/exec.go +++ b/internal/execext/exec.go @@ -55,7 +55,16 @@ func RunCommand(ctx context.Context, opts *RunCommandOptions) error { if err != nil { return err } - return r.Run(ctx, p) + + // We used to pass to interp.Runner a context that was cancelled on reception of a + // OS signal. This caused the Runner to terminate the subprocess abruptly. + // The correct behavior instead is for us to completely ignore the signal and let + // the subprocess deal with it. If the subprocess doesn't handle the signal, it will + // be terminated. If the subprocess does handle the signal, it knows better than us + // wether it wants to cleanup and terminate or do something different. + // See https://github.com/go-task/task/issues/458 for details. + // So now we pass an empty context just to make the API of interp.Runner happy + return r.Run(context.Background(), p) } // IsExitError returns true the given error is an exis status error