diff --git a/ksql-rest-app/src/main/java/io/confluent/ksql/rest/server/KsqlServerMain.java b/ksql-rest-app/src/main/java/io/confluent/ksql/rest/server/KsqlServerMain.java index 082aac37bfb2..cf005983f65c 100644 --- a/ksql-rest-app/src/main/java/io/confluent/ksql/rest/server/KsqlServerMain.java +++ b/ksql-rest-app/src/main/java/io/confluent/ksql/rest/server/KsqlServerMain.java @@ -19,6 +19,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; import io.confluent.ksql.properties.PropertiesUtil; +import io.confluent.ksql.rest.util.KsqlUncaughtExceptionHandler; import io.confluent.ksql.util.KsqlConfig; import io.confluent.ksql.util.KsqlServerException; import io.confluent.ksql.version.metrics.KsqlVersionCheckerAgent; @@ -50,6 +51,7 @@ public static void main(final String[] args) { System.getProperties() ); + Thread.setDefaultUncaughtExceptionHandler(new KsqlUncaughtExceptionHandler()); final String installDir = properties.getOrDefault("ksql.server.install.dir", ""); final KsqlConfig ksqlConfig = new KsqlConfig(properties); final String streamsStateDirPath = ksqlConfig.getKsqlStreamConfigProps().getOrDefault( diff --git a/ksql-rest-app/src/main/java/io/confluent/ksql/rest/util/KsqlUncaughtExceptionHandler.java b/ksql-rest-app/src/main/java/io/confluent/ksql/rest/util/KsqlUncaughtExceptionHandler.java new file mode 100644 index 000000000000..4d11ea5b36da --- /dev/null +++ b/ksql-rest-app/src/main/java/io/confluent/ksql/rest/util/KsqlUncaughtExceptionHandler.java @@ -0,0 +1,33 @@ +/* + * Copyright 2019 Confluent Inc. + * + * Licensed under the Confluent Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.confluent.io/confluent-community-license + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package io.confluent.ksql.rest.util; + +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import io.confluent.ksql.rest.server.KsqlServerMain; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +public class KsqlUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler { + + private static final Logger log = LoggerFactory.getLogger(KsqlServerMain.class); + + @SuppressFBWarnings + public void uncaughtException(final Thread t, final Throwable e) { + log.error("Unhandled exception caught in thread {}, error: {}", t.getName(), e.getStackTrace()); + System.exit(-1); + } +}