java
java copied to clipboard
InterruptedException during graceful shutdown with Kubernetes Java Client
Issue Description:
During the graceful shutdown process of my Spring Boot application in a Kubernetes environment, I noticed that the Kubernetes Client's informer and related threads are getting interrupted. Here's a snippet of the logs during the shutdown process:
2023-08-30 19:01:07.515 [SpringApplicationShutdownHook] INFO o.s.b.w.e.t.GracefulShutdown:shutDownGracefully:53 - Commencing graceful shutdown. Waiting for active requests to complete
2023-08-30 19:01:07.521 [tomcat-shutdown] INFO o.s.b.w.e.t.GracefulShutdown:doShutdown:78 - Graceful shutdown complete
2023-08-30 19:01:07.539 [controller-reflector-io.kubernetes.client.openapi.models.V1ConfigMap-1] INFO i.k.c.i.c.ReflectorRunnable:run:162 - class io.kubernetes.client.openapi.models.V1ConfigMap#Read timeout retry list and watch
2023-08-30 19:01:07.542 [informer-controller-V1ConfigMap] ERROR i.k.c.i.c.Controller:processLoop:164 - DefaultController#processLoop get interrupted null
java.lang.InterruptedException: null
at java.base/java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:1638)
at io.kubernetes.client.informer.cache.DeltaFIFO.pop(DeltaFIFO.java:318)
at io.kubernetes.client.informer.cache.Controller.processLoop(Controller.java:162)
at io.kubernetes.client.informer.cache.Controller.run(Controller.java:130)
at java.base/java.lang.Thread.run(Thread.java:833)
2023-08-30 19:01:07.542 [pool-11-thread-1] ERROR i.k.c.i.c.ProcessorListener:run:96 - processor interrupted: {}
java.lang.InterruptedException: null
at java.base/java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:1638)
at java.base/java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:435)
at io.kubernetes.client.informer.cache.ProcessorListener.run(ProcessorListener.java:58)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:833)
2023-08-30 19:01:09.860 [SpringApplicationShutdownHook] INFO o.s.o.j.LocalContainerEntityManagerFactoryBean:destroy:651 - Closing JPA EntityManagerFactory for persistence unit 'default'
Environment:
- Kubernetes Java Client Version: 13.0.2
- Spring Boot Version: 2.7.8
- implementation ("org.springframework.cloud:spring-cloud-starter-kubernetes-client-config:2.1.3")
- Java Version: 17
- Kubernetes Version: client : 1.17.0, server : 1.15.10
- Deployment Environment: Kubernetes
# configmap.yaml
apiVersion: v1
data:
application.properties: |
my-api.use-db=false
kind: ConfigMap
metadata:
name: my-api-config
namespace: my-namespace
..
# bootstrap.yaml
spring:
cloud:
kubernetes:
enabled: true
config:
sources:
- name: my-api-config
use-name-as-prefix: false
enabled: true
namespace: my-namespace
name: my-api-config
reload:
enabled: true
Expected Behavior:
The Kubernetes Client's threads (like the informer) should not be interrupted during a graceful shutdown, or should be able to handle interruptions more gracefully.
Actual Behavior:
The threads are getting interrupted and are throwing InterruptedException.
Question:
Is there a recommended way to cleanup Kubernetes Client resources during a pod's preStop hook or any other mechanism to avoid such interruptions?
Any insights or recommendations on how to handle this situation would be greatly appreciated.