This is an automated email from the ASF dual-hosted git repository.
wujimin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
The following commit(s) were added to refs/heads/master by this push:
new b65238e [SCB-1095]Timer task need catch all throwable to protected
from unexpected error
b65238e is described below
commit b65238e7a49d084b4459c14637452e94fab600d0
Author: liubao <[email protected]>
AuthorDate: Fri Dec 28 20:58:00 2018 +0800
[SCB-1095]Timer task need catch all throwable to protected from unexpected
error
---
.../apache/servicecomb/config/client/ApolloClient.java | 3 +--
.../servicecomb/config/client/ConfigCenterClient.java | 2 +-
.../foundation/common/event/SimpleSubscriber.java | 6 +++++-
.../foundation/metrics/MetricsBootstrap.java | 14 +++++++++++---
.../client/http/ServiceRegistryClientImpl.java | 13 ++++++++++++-
.../diagnosis/instance/InstanceCacheChecker.java | 2 ++
.../registry/RemoteServiceRegistry.java | 18 +++++++++++++++---
7 files changed, 47 insertions(+), 11 deletions(-)
diff --git
a/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/client/ApolloClient.java
b/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/client/ApolloClient.java
index 54a23fa..e2fa947 100644
---
a/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/client/ApolloClient.java
+++
b/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/client/ApolloClient.java
@@ -93,8 +93,7 @@ public class ApolloClient {
public void run() {
try {
refreshConfig();
- } catch (Exception e) {
-
+ } catch (Throwable e) {
LOGGER.error("client refresh thread exception ", e);
}
}
diff --git
a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/client/ConfigCenterClient.java
b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/client/ConfigCenterClient.java
index aabf1ef..56cb27e 100644
---
a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/client/ConfigCenterClient.java
+++
b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/client/ConfigCenterClient.java
@@ -252,7 +252,7 @@ public class ConfigCenterClient {
refreshConfig(configCenter, wait);
doWatch(configCenter);
}
- } catch (Exception e) {
+ } catch (Throwable e) {
LOGGER.error("client refresh thread exception", e);
}
}
diff --git
a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/event/SimpleSubscriber.java
b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/event/SimpleSubscriber.java
index e83a6bd..ea44dfe 100644
---
a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/event/SimpleSubscriber.java
+++
b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/event/SimpleSubscriber.java
@@ -70,7 +70,11 @@ public class SimpleSubscriber {
}
public void dispatchEvent(Object event) {
- dispatcher.accept(event);
+ try {
+ dispatcher.accept(event);
+ } catch (Throwable e) {
+ LOGGER.error("event process should not throw error. ", e);
+ }
}
private void syncDispatch(Object event) {
diff --git
a/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/MetricsBootstrap.java
b/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/MetricsBootstrap.java
index d2647f0..1ce656e 100644
---
a/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/MetricsBootstrap.java
+++
b/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/MetricsBootstrap.java
@@ -25,11 +25,15 @@ import java.util.concurrent.TimeUnit;
import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
import org.apache.servicecomb.foundation.metrics.registry.GlobalRegistry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import com.google.common.eventbus.EventBus;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
public class MetricsBootstrap {
+ private static final Logger LOGGER =
LoggerFactory.getLogger(MetricsBootstrap.class);
+
private GlobalRegistry globalRegistry;
private EventBus eventBus;
@@ -73,8 +77,12 @@ public class MetricsBootstrap {
}
public synchronized void pollMeters() {
- long secondInterval =
TimeUnit.MILLISECONDS.toSeconds(config.getMsPollInterval());
- PolledEvent polledEvent = globalRegistry.poll(secondInterval);
- eventBus.post(polledEvent);
+ try {
+ long secondInterval =
TimeUnit.MILLISECONDS.toSeconds(config.getMsPollInterval());
+ PolledEvent polledEvent = globalRegistry.poll(secondInterval);
+ eventBus.post(polledEvent);
+ } catch (Throwable e) {
+ LOGGER.error("poll meters error. ", e);
+ }
}
}
diff --git
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/http/ServiceRegistryClientImpl.java
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/http/ServiceRegistryClientImpl.java
index e73033a..12e3b8c 100644
---
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/http/ServiceRegistryClientImpl.java
+++
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/http/ServiceRegistryClientImpl.java
@@ -125,6 +125,10 @@ public final class ServiceRegistryClientImpl implements
ServiceRegistryClient {
return;
}
holder.setStatusCode(response.statusCode());
+ response.exceptionHandler(e -> {
+ LOGGER.error("error in processing response.", e);
+ countDownLatch.countDown();
+ });
response.bodyHandler(
bodyBuffer -> {
if (cls.getName().equals(HttpClientResponse.class.getName())) {
@@ -184,7 +188,10 @@ public final class ServiceRegistryClientImpl implements
ServiceRegistryClient {
return;
}
-
+ response.exceptionHandler(e -> {
+ LOGGER.error("error in processing response.", e);
+ countDownLatch.countDown();
+ });
response.bodyHandler(bodyBuffer -> {
ResponseWrapper responseWrapper = new ResponseWrapper();
responseWrapper.response = response;
@@ -209,6 +216,10 @@ public final class ServiceRegistryClientImpl implements
ServiceRegistryClient {
}
return;
}
+ response.exceptionHandler(e -> {
+ LOGGER.warn("failed to findInstances.", e);
+ countDownLatch.countDown();
+ });
response.bodyHandler(
bodyBuffer -> {
try {
diff --git
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/diagnosis/instance/InstanceCacheChecker.java
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/diagnosis/instance/InstanceCacheChecker.java
index ec27cb0..a71c7d0 100644
---
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/diagnosis/instance/InstanceCacheChecker.java
+++
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/diagnosis/instance/InstanceCacheChecker.java
@@ -102,6 +102,8 @@ public class InstanceCacheChecker {
instanceCacheResult.setDetail(String.format(
"revision is different, will be synchronized in next pull. local
revision=%s, remote revision=%s",
microserviceVersions.getRevision(),
microserviceInstances.getRevision()));
+ // better to change revision and more likely to find the correct
instances in next pull.
+ microserviceVersions.setRevision(null);
return instanceCacheResult;
}
diff --git
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/registry/RemoteServiceRegistry.java
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/registry/RemoteServiceRegistry.java
index 1dc0be8..eed2d08 100644
---
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/registry/RemoteServiceRegistry.java
+++
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/registry/RemoteServiceRegistry.java
@@ -52,9 +52,21 @@ public class RemoteServiceRegistry extends
AbstractServiceRegistry {
@Override
public void init() {
super.init();
- taskPool = new ScheduledThreadPoolExecutor(2,
- task -> new Thread(task, "Service Center Task"),
- (task, executor) -> LOGGER.warn("Too many pending tasks, reject " +
task.getClass().getName())
+ taskPool = new ScheduledThreadPoolExecutor(3,
+ task -> {
+ return new Thread(task) {
+ @Override
+ public void run() {
+ try {
+ setName("Service Center Task [" + task.toString() + "[" +
this.getId() + "]]");
+ super.run();
+ } catch (Throwable e) {
+ LOGGER.error("task {} execute error.", getName(), e);
+ }
+ }
+ };
+ },
+ (task, executor) -> LOGGER.warn("Too many pending tasks, reject " +
task.toString())
);
}