@@ -336,7 +336,7 @@ func (self *cmdObjRunner) runAndDetectCredentialRequest(
336
336
tr := io .TeeReader (handler .stdoutPipe , cmdWriter )
337
337
338
338
go utils .Safe (func () {
339
- self .processOutput (tr , handler .stdinPipe , promptUserForCredential , cmdObj )
339
+ self .processOutput (tr , handler .stdinPipe , promptUserForCredential , handler . close , cmdObj )
340
340
})
341
341
})
342
342
}
@@ -345,6 +345,7 @@ func (self *cmdObjRunner) processOutput(
345
345
reader io.Reader ,
346
346
writer io.Writer ,
347
347
promptUserForCredential func (CredentialType ) <- chan string ,
348
+ closeFunc func () error ,
348
349
cmdObj * CmdObj ,
349
350
) {
350
351
checkForCredentialRequest := self .getCheckForCredentialRequestFunc ()
@@ -358,25 +359,26 @@ func (self *cmdObjRunner) processOutput(
358
359
if ok {
359
360
responseChan := promptUserForCredential (askFor )
360
361
if responseChan == nil {
361
- // Returning a nil channel means we should kill the process.
362
- // Note that we don't break the loop after this, because we
363
- // still need to drain the output, otherwise the Wait() call
364
- // later might block .
365
- if err := Kill ( cmdObj . GetCmd () ); err != nil {
362
+ // Returning a nil channel means we should terminate the process.
363
+ // We achieve this by closing the pty that it's running in. Note that this won't
364
+ // work for the case where we're not running in a pty (i.e. on Windows), but
365
+ // in that case we'll never be prompted for credentials, so it's not a concern .
366
+ if err := closeFunc ( ); err != nil {
366
367
self .log .Error (err )
367
368
}
368
- } else {
369
- if task != nil {
370
- task .Pause ()
371
- }
372
- toInput := <- responseChan
373
- if task != nil {
374
- task .Continue ()
375
- }
376
- // If the return data is empty we don't write anything to stdin
377
- if toInput != "" {
378
- _ , _ = writer .Write ([]byte (toInput ))
379
- }
369
+ break
370
+ }
371
+
372
+ if task != nil {
373
+ task .Pause ()
374
+ }
375
+ toInput := <- responseChan
376
+ if task != nil {
377
+ task .Continue ()
378
+ }
379
+ // If the return data is empty we don't write anything to stdin
380
+ if toInput != "" {
381
+ _ , _ = writer .Write ([]byte (toInput ))
380
382
}
381
383
}
382
384
}
0 commit comments