@@ -425,7 +425,7 @@ func (t *ControllableTask) Kill() error {
425425
426426 log .Debug ("end transition loop done" )
427427
428- pid := t . rpc . TaskCmd . Process . Pid
428+ pid := int ( response . GetPid ())
429429 _ = t .rpc .Close ()
430430 t .rpc = nil
431431
@@ -439,9 +439,10 @@ func (t *ControllableTask) Kill() error {
439439
440440 killErrCh := make (chan error )
441441 // When killing we must always use syscall.Kill with a negative PID, in order to kill all
442- // children which were assigned the same PGID at launch
442+ // children which were assigned the same PGID at launch. Since we kill the child process,
443+ // it should also terminate the shell that is wrapping the command, we avoid using negative PID
443444 go func () {
444- err := syscall .Kill (- pid , syscall .SIGTERM )
445+ err := syscall .Kill (pid , syscall .SIGTERM )
445446 if err != nil {
446447 log .WithError (err ).
447448 WithField ("taskId" , t .ti .GetTaskID ()).
@@ -450,18 +451,31 @@ func (t *ControllableTask) Kill() error {
450451 killErrCh <- err
451452 }()
452453
453-
454454 // Set a small timeout to SIGTERM if SIGTERM fails or timeout passes,
455455 // we perform a SIGKILL.
456456 select {
457457 case killErr := <- killErrCh :
458458 if killErr == nil {
459- return killErr
459+ time .Sleep (10 * time .Second )
460+ if pidExists (pid ) {
461+ // SIGINT for the "Waiting for graceful device shutdown.
462+ // Hit Ctrl-C again to abort immediately" message.
463+ killErr = syscall .Kill (pid , syscall .SIGINT )
464+ if killErr != nil {
465+ log .WithError (killErr ).
466+ WithField ("taskId" , t .ti .GetTaskID ()).
467+ Warning ("could not gracefully kill task" )
468+ }
469+ }
470+ time .Sleep (10 * time .Second )
471+ if ! pidExists (pid ) {
472+ return killErr
473+ }
460474 }
461475 case <- time .After (10 * time .Second ):
462476 }
463477
464- killErr := syscall .Kill (- pid , syscall .SIGKILL )
478+ killErr := syscall .Kill (pid , syscall .SIGKILL )
465479 if killErr != nil {
466480 log .WithError (killErr ).
467481 WithField ("taskId" , t .ti .GetTaskID ()).
0 commit comments