From 17b61c22d32d51b7c554060f179a1447630414a4 Mon Sep 17 00:00:00 2001 From: Ryan Baxter Date: Tue, 16 Aug 2022 15:14:35 -0400 Subject: [PATCH] Catch and log any exceptions thrown within the executor service --- .../watcher/ConfigMapWatcherChangeDetector.java | 10 ++++++++-- .../watcher/SecretsWatcherChangeDetector.java | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/src/main/java/org/springframework/cloud/kubernetes/configuration/watcher/ConfigMapWatcherChangeDetector.java b/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/src/main/java/org/springframework/cloud/kubernetes/configuration/watcher/ConfigMapWatcherChangeDetector.java index 02d6ffb080..8c9a9f73ce 100644 --- a/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/src/main/java/org/springframework/cloud/kubernetes/configuration/watcher/ConfigMapWatcherChangeDetector.java +++ b/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/src/main/java/org/springframework/cloud/kubernetes/configuration/watcher/ConfigMapWatcherChangeDetector.java @@ -64,8 +64,14 @@ protected void onEvent(ConfigMap configMap) { + configMap.getMetadata().getName() + " to be published in " + k8SConfigurationProperties.getRefreshDelay().toMillis() + " milliseconds"); } - executorService.schedule(() -> triggerRefresh(configMap).subscribe(), - k8SConfigurationProperties.getRefreshDelay().toMillis(), TimeUnit.MILLISECONDS); + executorService.schedule(() -> { + try { + triggerRefresh(configMap).subscribe(); + } + catch (Throwable t) { + log.warn("Error when refreshing ConfigMap " + configMap.getMetadata().getName(), t); + } + }, k8SConfigurationProperties.getRefreshDelay().toMillis(), TimeUnit.MILLISECONDS); } else { if (log.isDebugEnabled()) { diff --git a/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/src/main/java/org/springframework/cloud/kubernetes/configuration/watcher/SecretsWatcherChangeDetector.java b/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/src/main/java/org/springframework/cloud/kubernetes/configuration/watcher/SecretsWatcherChangeDetector.java index e81adba52e..031da2d3d0 100644 --- a/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/src/main/java/org/springframework/cloud/kubernetes/configuration/watcher/SecretsWatcherChangeDetector.java +++ b/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/src/main/java/org/springframework/cloud/kubernetes/configuration/watcher/SecretsWatcherChangeDetector.java @@ -74,8 +74,14 @@ protected void onEvent(Secret secret) { + " to be published in " + k8SConfigurationProperties.getRefreshDelay().toMillis() + " milliseconds"); } - executorService.schedule(() -> triggerRefresh(secret).subscribe(), - k8SConfigurationProperties.getRefreshDelay().toMillis(), TimeUnit.MILLISECONDS); + executorService.schedule(() -> { + try { + triggerRefresh(secret).subscribe(); + } + catch (Throwable t) { + log.warn("Error when refreshing ConfigMap " + secret.getMetadata().getName(), t); + } + }, k8SConfigurationProperties.getRefreshDelay().toMillis(), TimeUnit.MILLISECONDS); } else { if (log.isDebugEnabled()) {