KAFKA-12699: Override the default handler for stream threads if the stream's handler is used (#12324)

Override the default handler for stream threads if the stream's handler is used. We do no want the java default handler triggering when a thread is replaced.

Reviewers: Anna Sophie Blee-Goldman <ableegoldman@apache.org>
This commit is contained in:
Walker Carlson 2022-07-19 15:35:26 -05:00 committed by GitHub
parent 693e283802
commit b62d8b975c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -471,6 +471,13 @@ public class KafkaStreams implements AutoCloseable {
exception -> handleStreamsUncaughtException(exception, userStreamsUncaughtExceptionHandler, false)
);
}
processStreamThread(thread -> thread.setUncaughtExceptionHandler((t, e) -> { }
));
if (globalStreamThread != null) {
globalStreamThread.setUncaughtExceptionHandler((t, e) -> { }
);
}
} else {
throw new IllegalStateException("Can only set UncaughtExceptionHandler before calling start(). " +
"Current state is: " + state);

View File

@ -176,6 +176,12 @@ public class StreamsUncaughtExceptionHandlerIntegrationTest {
testReplaceThreads(2);
}
@Test
public void shouldReplaceThreadsWithoutJavaHandler() throws InterruptedException {
Thread.setDefaultUncaughtExceptionHandler((t, e) -> fail("exception thrown"));
testReplaceThreads(2);
}
@Test
public void shouldReplaceSingleThread() throws InterruptedException {
testReplaceThreads(1);