Skip to content

Commit a11262f

Browse files
authored
Merge pull request #666 from yue9944882/bugfix/fixes-listener-quiting
Fixes unexpectedly listener quitting leads to OOM
2 parents 2707b58 + b18dbfd commit a11262f

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

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

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,36 @@ public void run() {
4545
Notification obj = queue.take();
4646
if (obj instanceof UpdateNotification) {
4747
UpdateNotification notification = (UpdateNotification) obj;
48-
this.handler.onUpdate(
49-
(ApiType) notification.getOldObj(), (ApiType) notification.getNewObj());
48+
try {
49+
this.handler.onUpdate(
50+
(ApiType) notification.getOldObj(), (ApiType) notification.getNewObj());
51+
} catch (Throwable t) {
52+
// Catch all exceptions here so that listeners won't quit unexpectedly
53+
log.error("failed invoking UPDATE event handler: {}", t.getMessage());
54+
continue;
55+
}
5056
} else if (obj instanceof AddNotification) {
5157
AddNotification notification = (AddNotification) obj;
52-
this.handler.onAdd((ApiType) notification.getNewObj());
58+
try {
59+
this.handler.onAdd((ApiType) notification.getNewObj());
60+
} catch (Throwable t) {
61+
// Catch all exceptions here so that listeners won't quit unexpectedly
62+
log.error("failed invoking ADD event handler: {}", t.getMessage());
63+
continue;
64+
}
5365
} else if (obj instanceof DeleteNotification) {
5466
Object deletedObj = ((DeleteNotification) obj).getOldObj();
55-
if (deletedObj instanceof DeltaFIFO.DeletedFinalStateUnknown) {
56-
this.handler.onDelete(
57-
((DeltaFIFO.DeletedFinalStateUnknown<ApiType>) deletedObj).getObj(), true);
58-
} else {
59-
this.handler.onDelete((ApiType) deletedObj, false);
67+
try {
68+
if (deletedObj instanceof DeltaFIFO.DeletedFinalStateUnknown) {
69+
this.handler.onDelete(
70+
((DeltaFIFO.DeletedFinalStateUnknown<ApiType>) deletedObj).getObj(), true);
71+
} else {
72+
this.handler.onDelete((ApiType) deletedObj, false);
73+
}
74+
} catch (Throwable t) {
75+
// Catch all exceptions here so that listeners won't quit unexpectedly
76+
log.error("failed invoking DELETE event handler: {}", t.getMessage());
77+
continue;
6078
}
6179
} else {
6280
throw new BadNotificationException("unrecognized notification");
@@ -72,7 +90,9 @@ public void add(Notification<ApiType> obj) {
7290
if (obj == null) {
7391
return;
7492
}
75-
this.queue.add(obj);
93+
if (!this.queue.offer(obj)) {
94+
log.warn("notification queue full!");
95+
}
7696
}
7797

7898
public void determineNextResync(DateTime now) {

0 commit comments

Comments
 (0)