Skip to content

Commit b9c5065

Browse files
committed
Fix StackOverflowError on Windows. Fixes #5730
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
1 parent f545640 commit b9c5065

File tree

1 file changed

+1
-8
lines changed

1 file changed

+1
-8
lines changed

src/main/java/com/google/devtools/build/lib/shell/Consumers.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -244,27 +244,20 @@ public void waitForCompletion() throws IOException {
244244
}
245245
}
246246

247-
/**
248-
* Factory which produces threads with a 32K stack size.
249-
*/
250247
private static class AccumulatorThreadFactory implements ThreadFactory {
251248

252-
private static final int THREAD_STACK_SIZE = 32 * 1024;
253-
254249
private static AtomicInteger threadInitNumber = new AtomicInteger(0);
255250

256251
@Override
257252
public Thread newThread(final Runnable runnable) {
258253
final Thread t =
259254
new Thread(null,
260255
runnable,
261-
"Command-Accumulator-Thread-" + threadInitNumber.getAndIncrement(),
262-
THREAD_STACK_SIZE);
256+
"Command-Accumulator-Thread-" + threadInitNumber.getAndIncrement());
263257
// Don't let this thread hold up JVM exit
264258
t.setDaemon(true);
265259
return t;
266260
}
267-
268261
}
269262

270263
/**

0 commit comments

Comments
 (0)