Skip to content

Commit

Permalink
feat: add global UncaughtExceptionHandler to all threads (can be over…
Browse files Browse the repository at this point in the history
…ridden)
  • Loading branch information
stevenpyzhang committed Sep 26, 2019
1 parent bf51808 commit 4a9f746
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 4a9f746

Please sign in to comment.