@@ -50,8 +50,6 @@ public class ReflectorRunnable<
50
50
51
51
private boolean isLastSyncResourceVersionUnavailable ;
52
52
53
- private Watchable <ApiType > watch ;
54
-
55
53
private ListerWatcher <ApiType , ApiListType > listerWatcher ;
56
54
57
55
private DeltaFIFO store ;
@@ -91,16 +89,11 @@ public void run() {
91
89
try {
92
90
this .lastSyncResourceVersion = initialLoad ();
93
91
this .isLastSyncResourceVersionUnavailable = false ;
94
-
92
+ Watchable < ApiType > watch = null ;
95
93
if (log .isDebugEnabled ()) {
96
94
log .debug ("{}#Start watching with {}..." , apiTypeClass , lastSyncResourceVersion );
97
95
}
98
- while (true ) {
99
- if (!isActive .get ()) {
100
- closeWatch ();
101
- return ;
102
- }
103
-
96
+ while (isActive .get ()) {
104
97
try {
105
98
if (log .isDebugEnabled ()) {
106
99
log .debug (
@@ -110,21 +103,14 @@ public void run() {
110
103
long jitteredWatchTimeoutSeconds =
111
104
Double .valueOf (REFLECTOR_WATCH_CLIENTSIDE_TIMEOUT .getSeconds () * (1 + Math .random ()))
112
105
.longValue ();
113
- Watchable < ApiType > newWatch =
106
+ watch =
114
107
listerWatcher .watch (
115
108
new CallGeneratorParams (
116
109
Boolean .TRUE ,
117
110
lastSyncResourceVersion ,
118
111
Long .valueOf (jitteredWatchTimeoutSeconds ).intValue ()));
119
112
120
- synchronized (this ) {
121
- if (!isActive .get ()) {
122
- newWatch .close ();
123
- continue ;
124
- }
125
- watch = newWatch ;
126
- }
127
- watchHandler (newWatch );
113
+ watchHandler (watch );
128
114
} catch (WatchExpiredException e ) {
129
115
// Watch calls were failed due to expired resource-version. Returning
130
116
// to unwind the list-watch loops so that we can respawn a new round
@@ -155,7 +141,13 @@ public void run() {
155
141
this .exceptionHandler .accept (apiTypeClass , t );
156
142
return ;
157
143
} finally {
158
- closeWatch ();
144
+ if (watch != null ) {
145
+ try {
146
+ watch .close ();
147
+ } catch (IOException e ) {
148
+ log .warn ("{}#Error while closing watcher" , this .apiTypeClass , e );
149
+ }
150
+ }
159
151
}
160
152
}
161
153
} catch (ApiException e ) {
@@ -181,13 +173,6 @@ public void stop() {
181
173
}
182
174
}
183
175
184
- private synchronized void closeWatch () throws IOException {
185
- if (watch != null ) {
186
- watch .close ();
187
- watch = null ;
188
- }
189
- }
190
-
191
176
private String initialLoad () throws ApiException {
192
177
ApiListType list =
193
178
listerWatcher .list (
@@ -284,6 +269,11 @@ private void watchHandler(Watchable<ApiType> watch) {
284
269
log .debug ("{}#Receiving resourceVersion {}" , apiTypeClass , lastSyncResourceVersion );
285
270
}
286
271
}
272
+ try {
273
+ watch .close ();
274
+ } catch (IOException e ) {
275
+ log .warn ("{}#Error while closing watcher" , this .apiTypeClass , e );
276
+ }
287
277
}
288
278
289
279
static <ApiType extends KubernetesObject > void defaultWatchErrorHandler (
0 commit comments