Skip to content

Commit bc80b69

Browse files
committed
fixes listener quiting unexpectedly
1 parent 2707b58 commit bc80b69

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

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

Lines changed: 26 additions & 8 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");

0 commit comments

Comments
 (0)