Skip to content

Commit

Permalink
Revert "Always check available() in InputPumper to avoid burning …
Browse files Browse the repository at this point in the history
…CPU (#4095)" (#4159)

Fixes #4158

This hits some JVM limitations that significantly slow down the process
exit, unnecessarily. Added a comment to the code so we don't forget
again
  • Loading branch information
lihaoyi authored Dec 18, 2024
1 parent ded5dd9 commit d3e5d50
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion main/client/src/mill/main/client/InputPumper.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ public void run() {
byte[] buffer = new byte[1024];
try {
while (running) {
if (!runningCheck.getAsBoolean()) running = false;
if (!runningCheck.getAsBoolean()) {
running = false;
// We need to check `.available` and avoid calling `.read`, because if we call `.read`
// and there is nothing to read, it can unnecessarily delay the JVM exit by 350ms
// https://stackoverflow.com/questions/48951611/blocking-on-stdin-makes-java-process-take-350ms-more-to-exit
} else if (checkAvailable && src.available() == 0) Thread.sleep(1);
else {
int n;
try {
Expand Down

0 comments on commit d3e5d50

Please sign in to comment.