Skip to content

Commit

Permalink
Fix StackOverflowError on Windows. Fixes #5730
Browse files Browse the repository at this point in the history
We found that with JDK9 and up Bazel would sometimes crash
with a StackOverflowError in one of the Command-Accumulator-Thread-*
threads. We experimentally found that this error was due to these
threads being constrained to a 32KiB stack size. The default stack
size for JVM threads on most 64-bit systems is 1MiB (So that's 3%
of the default). The purpose of the Command-Accumulator-Threads
is to read stdout/stderr from processes that Bazel launches locally.

The proposed fix is to just use the system default stack size for
these threads. The alternative is to increase the size limit to
some arbitrary number that happens to work, but this is likely
premature optimization and I'd like to avoid that if possible. We
further found that this code even predates Blaze/Bazel and is
from 2005.

PiperOrigin-RevId: 208009940
  • Loading branch information
buchgr authored and Copybara-Service committed Aug 9, 2018
1 parent 4e3a64d commit d215b64
Showing 1 changed file with 1 addition and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -244,27 +244,20 @@ public void waitForCompletion() throws IOException {
}
}

/**
* Factory which produces threads with a 32K stack size.
*/
private static class AccumulatorThreadFactory implements ThreadFactory {

private static final int THREAD_STACK_SIZE = 32 * 1024;

private static AtomicInteger threadInitNumber = new AtomicInteger(0);

@Override
public Thread newThread(final Runnable runnable) {
final Thread t =
new Thread(null,
runnable,
"Command-Accumulator-Thread-" + threadInitNumber.getAndIncrement(),
THREAD_STACK_SIZE);
"Command-Accumulator-Thread-" + threadInitNumber.getAndIncrement());
// Don't let this thread hold up JVM exit
t.setDaemon(true);
return t;
}

}

/**
Expand Down

0 comments on commit d215b64

Please sign in to comment.