Skip to content

Commit 1bb6ee0

Browse files
committed
Kill background fetch when it requests a passphrase
Previously we would enter a newline at the password prompt, which would cause the fetch to fail. The problem with this was that if you have many remotes, the fetch would sometimes hang for some reason; I don't totally understand how that happened, but I guess the many ssh processes requesting passwords would somehow interfere with each other. Avoid this by simply killing the git fetch process the moment it requests the first password.
1 parent 52d3446 commit 1bb6ee0

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

pkg/commands/oscommands/cmd_obj_runner.go

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -294,14 +294,10 @@ const (
294294
Token
295295
)
296296

297-
// Whenever we're asked for a password we just enter a newline, which will
298-
// eventually cause the command to fail.
297+
// Whenever we're asked for a password we return a nil channel to tell the
298+
// caller to kill the process.
299299
var failPromptFn = func(CredentialType) <-chan string {
300-
ch := make(chan string)
301-
go func() {
302-
ch <- "\n"
303-
}()
304-
return ch
300+
return nil
305301
}
306302

307303
func (self *cmdObjRunner) runWithCredentialHandling(cmdObj *CmdObj) error {
@@ -360,16 +356,26 @@ func (self *cmdObjRunner) processOutput(
360356
askFor, ok := checkForCredentialRequest(newBytes)
361357
if ok {
362358
responseChan := promptUserForCredential(askFor)
363-
if task != nil {
364-
task.Pause()
365-
}
366-
toInput := <-responseChan
367-
if task != nil {
368-
task.Continue()
369-
}
370-
// If the return data is empty we don't write anything to stdin
371-
if toInput != "" {
372-
_, _ = writer.Write([]byte(toInput))
359+
if responseChan == nil {
360+
// Returning a nil channel means we should kill the process.
361+
// Note that we don't break the loop after this, because we
362+
// still need to drain the output, otherwise the Wait() call
363+
// later might block.
364+
if err := Kill(cmdObj.GetCmd()); err != nil {
365+
self.log.Error(err)
366+
}
367+
} else {
368+
if task != nil {
369+
task.Pause()
370+
}
371+
toInput := <-responseChan
372+
if task != nil {
373+
task.Continue()
374+
}
375+
// If the return data is empty we don't write anything to stdin
376+
if toInput != "" {
377+
_, _ = writer.Write([]byte(toInput))
378+
}
373379
}
374380
}
375381
}

0 commit comments

Comments
 (0)