From 2c705c6f9123f0cf3ed90cb7dcca9a47bbd87b1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arda=20G=C3=BC=C3=A7l=C3=BC?= Date: Fri, 16 Aug 2024 16:13:01 +0300 Subject: [PATCH] Increate timeout to 10sec and shortcut when ctx deadline is exceeded Kubernetes-commit: ca2c9c64b489d14352e9b6f4c827506a5653a569 --- pkg/cmd/cp/cp.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/cmd/cp/cp.go b/pkg/cmd/cp/cp.go index 9702d850..68b55bf2 100644 --- a/pkg/cmd/cp/cp.go +++ b/pkg/cmd/cp/cp.go @@ -280,7 +280,7 @@ func (o *CopyOptions) checkDestinationIsDir(dest fileSpec) error { Executor: &exec.DefaultRemoteExecutor{}, } - ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() done := make(chan error) @@ -291,7 +291,7 @@ func (o *CopyOptions) checkDestinationIsDir(dest fileSpec) error { select { case <-ctx.Done(): - return fmt.Errorf("timeout exceeded while checking the destination") + return ctx.Err() case err := <-done: return err } @@ -310,6 +310,10 @@ func (o *CopyOptions) copyToPod(src, dest fileSpec, options *exec.ExecOptions) e // If no error, dest.File was found to be a directory. // Copy specified src into it destFile = destFile.Join(srcFile.Base()) + } else if errors.Is(err, context.DeadlineExceeded) { + // we haven't decided destination is directory or not because context timeout is exceeded. + // That's why, we should shortcut the process in here. + return err } go func(src localPath, dest remotePath, writer io.WriteCloser) {