Skip to content

formatDiff fails with "git diff took too long to terminate" on a diff larger than 64 KB #257

Closed

Description

@abashev

What happens

./gradlew formatDiff fails after 30 seconds when a project's uncommitted changes make a diff larger than the pipe buffer of the operating system, 64 KB on Linux and macOS:

Execution failed for task ':open-java-format-idea-plugin:formatDiff'.
> git diff took too long to terminate

Seen on macOS aarch64 with a diff of 70,737 bytes (git diff -U0 HEAD | wc -c), the work for #223. With a small diff the same command passes.

Why

FormatDiff.gitCommand starts git diff -U0 HEAD <dir>, waits up to 30 seconds for it to exit, and reads its standard output only after that:

Process process = new ProcessBuilder().command(args).directory(dir.toFile()).start();

Preconditions.checkState(process.waitFor(30, TimeUnit.SECONDS), "git diff took too long to terminate");
...
process.getInputStream().transferTo(baos);

Nobody reads the pipe while git writes to it, so once the pipe is full git blocks and never exits. FormatterCommandRunner.runWithStdin has the comment for the same trap: "Make sure to drain stdout before waiting for the process to exit as this can result in a deadlock otherwise."

Read from the code, not tried: the standard error is a pipe too, read only when the exit code is not 0, so a git that writes more than a pipe's worth of warnings would hang the same way. And git rev-parse --show-toplevel, which goes through the same method, would fail with "git diff took too long" as well.

Proposal

  • Read the output before waiting for the process, with the standard error redirected to a file or read on its own thread.
  • Name the command that timed out in the message.
  • A test with a diff larger than 64 KB: FormatDiffTest has none.

Until then, a large change can be formatted with the command line: -i on new files, -i --lines <from>:<to> --skip-sorting-imports --skip-removing-unused-imports on modified ones.

Activity

  1. added
    bug
    on Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions