You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
formatDiff fails with "git diff took too long to terminate" on a diff larger than 64 KB #257
./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:
Processprocess = newProcessBuilder().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