Skip to content

Commit ca2c9c6

Browse files
committed
Increate timeout to 10sec and shortcut when ctx deadline is exceeded
1 parent 78ae67a commit ca2c9c6

File tree

1 file changed

+6
-2
lines changed
  • staging/src/k8s.io/kubectl/pkg/cmd/cp

1 file changed

+6
-2
lines changed

staging/src/k8s.io/kubectl/pkg/cmd/cp/cp.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ func (o *CopyOptions) checkDestinationIsDir(dest fileSpec) error {
280280
Executor: &exec.DefaultRemoteExecutor{},
281281
}
282282

283-
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
283+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
284284
defer cancel()
285285

286286
done := make(chan error)
@@ -291,7 +291,7 @@ func (o *CopyOptions) checkDestinationIsDir(dest fileSpec) error {
291291

292292
select {
293293
case <-ctx.Done():
294-
return fmt.Errorf("timeout exceeded while checking the destination")
294+
return ctx.Err()
295295
case err := <-done:
296296
return err
297297
}
@@ -310,6 +310,10 @@ func (o *CopyOptions) copyToPod(src, dest fileSpec, options *exec.ExecOptions) e
310310
// If no error, dest.File was found to be a directory.
311311
// Copy specified src into it
312312
destFile = destFile.Join(srcFile.Base())
313+
} else if errors.Is(err, context.DeadlineExceeded) {
314+
// we haven't decided destination is directory or not because context timeout is exceeded.
315+
// That's why, we should shortcut the process in here.
316+
return err
313317
}
314318

315319
go func(src localPath, dest remotePath, writer io.WriteCloser) {

0 commit comments

Comments
 (0)