Skip to content

Commit fdccec2

Browse files
yue9944882brendandburns
authored andcommitted
graceful shutdown sharedprocessor
1 parent c59623f commit fdccec2

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

util/src/main/java/io/kubernetes/client/informer/cache/SharedProcessor.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,16 @@
2323
import java.util.concurrent.locks.ReentrantReadWriteLock;
2424
import org.apache.commons.collections4.CollectionUtils;
2525
import org.joda.time.DateTime;
26+
import org.slf4j.Logger;
27+
import org.slf4j.LoggerFactory;
2628

2729
/*
2830
* SharedProcessor class manages all the registered ProcessorListener and distributes notifications.
2931
*/
3032
public class SharedProcessor<ApiType extends KubernetesObject> {
3133

34+
private static final Logger log = LoggerFactory.getLogger(SharedProcessor.class);
35+
3236
private ReadWriteLock lock = new ReentrantReadWriteLock();
3337

3438
private List<ProcessorListener<ApiType>> listeners;
@@ -155,16 +159,16 @@ public void stop() {
155159
} finally {
156160
lock.writeLock().unlock();
157161
}
158-
// Disable new tasks from being submitted
159-
executorService.shutdown();
162+
// Interrupts running listeners by signalling InterruptedException
163+
executorService.shutdownNow();
160164
try {
161-
// Wait a while for existing tasks to terminate
165+
// Hold until all the listeners exits
162166
if (!executorService.awaitTermination(timeout.toMillis(), TimeUnit.MILLISECONDS)) {
163-
// Cancel currently executing tasks
164-
executorService.shutdownNow();
167+
log.warn(
168+
"SharedProcessors wasn't gracefully terminated, there can be listener thread leakage");
165169
}
166170
} catch (InterruptedException e) {
167-
executorService.shutdownNow();
171+
log.error("Graceful shutdown process of SharedProcessors was interrupted");
168172
}
169173
}
170174
}

0 commit comments

Comments
 (0)