Skip to content

[Tool] Fix background git fetch hanging silently when asking for an SSH passphrase#185219

Open
bkonyi wants to merge 1 commit intoflutter:masterfrom
bkonyi:fix-git-ssh-hang-8939177479079620407
Open

[Tool] Fix background git fetch hanging silently when asking for an SSH passphrase#185219
bkonyi wants to merge 1 commit intoflutter:masterfrom
bkonyi:fix-git-ssh-hang-8939177479079620407

Conversation

@bkonyi
Copy link
Copy Markdown
Contributor

@bkonyi bkonyi commented Apr 17, 2026

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 #184309

…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>
@github-actions github-actions bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Apr 17, 2026
@bkonyi bkonyi added CICD Run CI/CD and removed tool Affects the "flutter" command-line tool. See also t: labels. labels Apr 17, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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'],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
['-c', 'core.sshCommand=ssh -o BatchMode=yes', 'fetch', '--tags'],
[...Git.silentSshArgs, 'fetch', '--tags'],

Comment on lines +143 to +145
static const _noPromptEnvironment = <String, String>{
'GIT_TERMINAL_PROMPT': '0',
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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
  1. Avoid duplicating state: Keep only one source of truth. (link)

Comment on lines +395 to +396
// Use BatchMode to prevent ssh-agent hanging in the background.
await _run(_git, ['-c', 'core.sshCommand=ssh -o BatchMode=yes', 'fetch', '--tags']);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
// 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'],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider using the suggested Git.silentSshArgs constant here to avoid duplication and centralize the SSH configuration.

Suggested change
['-c', 'core.sshCommand=ssh -o BatchMode=yes', 'fetch', flutterGit, '--tags', '-f'],
[...Git.silentSshArgs, 'fetch', flutterGit, '--tags', '-f'],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flutter_tool gets stuck silently if git asks for passphrase

1 participant