From 1bb6ee0d80821c20b608189903b495460ca54b41 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Fri, 23 May 2025 14:55:31 +0200 Subject: [PATCH] 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. --- pkg/commands/oscommands/cmd_obj_runner.go | 40 +++++++++++++---------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/pkg/commands/oscommands/cmd_obj_runner.go b/pkg/commands/oscommands/cmd_obj_runner.go index c8500d93d..2d0b7034e 100644 --- a/pkg/commands/oscommands/cmd_obj_runner.go +++ b/pkg/commands/oscommands/cmd_obj_runner.go @@ -294,14 +294,10 @@ const ( Token ) -// Whenever we're asked for a password we just enter a newline, which will -// eventually cause the command to fail. +// Whenever we're asked for a password we return a nil channel to tell the +// caller to kill the process. var failPromptFn = func(CredentialType) <-chan string { - ch := make(chan string) - go func() { - ch <- "\n" - }() - return ch + return nil } func (self *cmdObjRunner) runWithCredentialHandling(cmdObj *CmdObj) error { @@ -360,16 +356,26 @@ func (self *cmdObjRunner) processOutput( askFor, ok := checkForCredentialRequest(newBytes) if ok { responseChan := promptUserForCredential(askFor) - if task != nil { - task.Pause() - } - toInput := <-responseChan - if task != nil { - task.Continue() - } - // If the return data is empty we don't write anything to stdin - if toInput != "" { - _, _ = writer.Write([]byte(toInput)) + if responseChan == nil { + // Returning a nil channel means we should kill the process. + // Note that we don't break the loop after this, because we + // still need to drain the output, otherwise the Wait() call + // later might block. + if err := Kill(cmdObj.GetCmd()); err != nil { + self.log.Error(err) + } + } else { + if task != nil { + task.Pause() + } + toInput := <-responseChan + if task != nil { + task.Continue() + } + // If the return data is empty we don't write anything to stdin + if toInput != "" { + _, _ = writer.Write([]byte(toInput)) + } } } }