From 8e72211db931e66b579c9290bf29aad00c37a490 Mon Sep 17 00:00:00 2001 From: Eric Zhao Date: Fri, 25 Jan 2019 13:48:31 +0800 Subject: [PATCH] Add catch throwable logic in ClusterStateManager to detect fatal error when loading SPI Signed-off-by: Eric Zhao --- .../sentinel/cluster/ClusterStateManager.java | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/cluster/ClusterStateManager.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/cluster/ClusterStateManager.java index 3c15f87d..068bb88d 100644 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/cluster/ClusterStateManager.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/cluster/ClusterStateManager.java @@ -224,17 +224,22 @@ public final class ClusterStateManager { if (state == mode) { return true; } - switch (state) { - case CLUSTER_CLIENT: - return setToClient(); - case CLUSTER_SERVER: - return setToServer(); - case CLUSTER_NOT_STARTED: - setStop(); - return true; - default: - RecordLog.warn("[ClusterStateManager] Ignoring unknown cluster state: " + state); - return false; + try { + switch (state) { + case CLUSTER_CLIENT: + return setToClient(); + case CLUSTER_SERVER: + return setToServer(); + case CLUSTER_NOT_STARTED: + setStop(); + return true; + default: + RecordLog.warn("[ClusterStateManager] Ignoring unknown cluster state: " + state); + return false; + } + } catch (Throwable t) { + RecordLog.warn("[ClusterStateManager] Fatal error when applying state: " + state, t); + return false; } }