allthingssecurity commented on code in PR #27302:
URL: https://github.com/apache/camel/pull/27302#discussion_r4171292218
##########
components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesHelper.java:
##########
@@ -90,6 +93,27 @@ public static void close(Runnable runnable, Supplier<Watch>
watchGetter) {
}
}
+ /**
+ * Watches again when the Kubernetes client closed the watch of a consumer
with an error. The client reconnects a
+ * watch by itself after transient errors, and only closes it with an
exception when it gives up: when the API
+ * server answers 410 Gone because the resource version of the watch is
too old (which happens to long-running
+ * watches), or when the reconnect limit is reached. The consumer would
then not receive any event anymore.
+ *
+ * @param consumer the consumer of the watch
+ * @param executor the executor of the consumer
+ * @param task the task that creates the watch of the consumer
+ */
+ public static void watchAgain(ServiceSupport consumer, ExecutorService
executor, Runnable task) {
+ if (consumer.isRunAllowed() && executor != null &&
!executor.isShutdown()) {
+ LOG.info("Watching again for {} after its watch was closed",
consumer);
+ try {
+ executor.submit(task);
+ } catch (RejectedExecutionException e) {
+ LOG.debug("Cannot watch again for {} as it is stopping",
consumer, e);
+ }
+ }
+ }
Review Comment:
Good point, done in f94ad1f36fc6: `watchAgain` now waits one second before
it creates the new watch. The wait runs on the consumer's own executor thread,
so a stop (`shutdownNow`) ends it at once and no new watch is created. Since
the fabric8 client has already retried with its own backoff before it closes
the watch with an exception, a fixed short delay seemed enough to avoid a tight
loop; happy to make it exponential if preferred. The camel-kubernetes tests
pass (156).
_Claude Code on behalf of allthingssecurity_
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]