[Tool] Fix background git fetch hanging silently when asking for an SSH passphrase#185219
[Tool] Fix background git fetch hanging silently when asking for an SSH passphrase#185219bkonyi wants to merge 1 commit intoflutter:masterfrom
Conversation
…phrase When using ssh-agent or ssh identities without caching, background git operations like `git fetch --tags` would silently hang forever when prompting for user input (such as an SSH passphrase). This adds `-c core.sshCommand=ssh -o BatchMode=yes` to specific background tag fetching commands to force SSH to fail fast instead of hanging. Additionally, `GIT_TERMINAL_PROMPT=0` was added to all background git environments to suppress other generic terminal prompts. Fixes flutter#184309 Co-authored-by: bkonyi <24210656+bkonyi@users.noreply.github.com>
There was a problem hiding this comment.
Code Review
This pull request implements measures to prevent background Git operations from hanging by disabling terminal prompts and enabling SSH batch mode. The review feedback recommends centralizing the SSH configuration arguments into a constant to reduce code duplication and improve support for diverse SSH environments and platforms.
| // Use BatchMode to prevent ssh-agent hanging in the background. | ||
| await globals.git.run( | ||
| ['fetch', '--tags'], | ||
| ['-c', 'core.sshCommand=ssh -o BatchMode=yes', 'fetch', '--tags'], |
There was a problem hiding this comment.
Hardcoding ssh and overriding core.sshCommand can break connectivity for users with custom SSH configurations. For example, users who rely on specific identity files or proxies via core.sshCommand in their global .gitconfig will have those settings ignored. Additionally, Windows users using PuTTY (plink) as their SSH client may encounter failures if ssh is not in their path or not configured with their keys. Using a constant (as suggested in git.dart) would at least centralize this logic for future platform-specific fixes.
| ['-c', 'core.sshCommand=ssh -o BatchMode=yes', 'fetch', '--tags'], | |
| [...Git.silentSshArgs, 'fetch', '--tags'], |
| static const _noPromptEnvironment = <String, String>{ | ||
| 'GIT_TERMINAL_PROMPT': '0', | ||
| }; |
There was a problem hiding this comment.
The magic string '-c', 'core.sshCommand=ssh -o BatchMode=yes' is duplicated across multiple files and tests. To adhere to the "Avoid duplicating state" principle (Style Guide line 30), consider defining these arguments as a constant here in the Git class. This provides a centralized location to handle future improvements, such as supporting alternative SSH clients like PuTTY (plink) which require different flags (e.g., -batch).
static const _noPromptEnvironment = <String, String>{
'GIT_TERMINAL_PROMPT': '0',
};
/// Git arguments to force SSH into batch mode, preventing hangs during background operations.
static const List<String> silentSshArgs = <String>['-c', 'core.sshCommand=ssh -o BatchMode=yes'];References
- Avoid duplicating state: Keep only one source of truth. (link)
| // Use BatchMode to prevent ssh-agent hanging in the background. | ||
| await _run(_git, ['-c', 'core.sshCommand=ssh -o BatchMode=yes', 'fetch', '--tags']); |
There was a problem hiding this comment.
The comment mentions preventing ssh-agent from hanging, but it is actually the ssh process that hangs while waiting for user input (such as a passphrase for a key, whether or not an agent is involved). Also, consider using the suggested constant to reduce duplication.
| // Use BatchMode to prevent ssh-agent hanging in the background. | |
| await _run(_git, ['-c', 'core.sshCommand=ssh -o BatchMode=yes', 'fetch', '--tags']); | |
| // Use BatchMode to prevent SSH from hanging while waiting for user interaction. | |
| await _run(_git, [...Git.silentSshArgs, 'fetch', '--tags']); |
| git.runSync(['fetch', flutterGit, '--tags', '-f'], workingDirectory: workingDirectory); | ||
| // Use BatchMode to prevent ssh-agent hanging in the background. | ||
| git.runSync( | ||
| ['-c', 'core.sshCommand=ssh -o BatchMode=yes', 'fetch', flutterGit, '--tags', '-f'], |
There was a problem hiding this comment.
When using ssh-agent or ssh identities without caching, background git operations like
git fetch --tagswould silently hang forever when prompting for user input (such as an SSH passphrase). This adds-c core.sshCommand=ssh -o BatchMode=yesto specific background tag fetching commands to force SSH to fail fast instead of hanging. Additionally,GIT_TERMINAL_PROMPT=0was added to all background git environments to suppress other generic terminal prompts.Fixes #184309