Skip to content

Commit

Permalink
fix fabric8io#3484: ensuring that only one close method is called suc…
Browse files Browse the repository at this point in the history
…cessfully
  • Loading branch information
shawkins authored and manusa committed Sep 22, 2021
1 parent cc4d318 commit a9366ef
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Fix #3445: TokenRefreshInterceptor throws when running incluster config
* Fix #3456: io.fabric8:crd-generator README should reference crd-generator-apt instead of now removed crd-generator artifact
* Fix #3384: preventing NPE from being logged with pod execs.
* Fix #3484: Ensuring that the informer isWatching flag is correctly reported

#### Improvements
* Fix #3398: Added javadocs explaining the wait parameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,18 @@ final void close(WatcherException cause) {
// proactively close the request (it will be called again in close)
// for reconnecting watchers, we may not complete onClose for a while
closeRequest();
if (!watcher.reconnecting() && forceClosed.getAndSet(true)) {
if (forceClosed.get()) {
logger.debug("Ignoring duplicate firing of onClose event");
} else {
watcher.onClose(cause);
} else {
boolean success = false;
try {
watcher.onClose(cause);
success = true;
} finally {
if (success || !watcher.reconnecting()) {
forceClosed.set(true);
}
}
}
close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void eventReceived(Action action, T resource) {
throw new KubernetesClientException("Unrecognized resource");
}
if (log.isDebugEnabled()) {
log.debug("Event received {} {}# resourceVersion {}", action.name(), resource.getKind(), resource.getMetadata().getResourceVersion());
log.debug("Event received {} {} resourceVersion {}", action.name(), resource.getKind(), resource.getMetadata().getResourceVersion());
}
switch (action) {
case ERROR:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,24 @@ void closeEventWithExceptionIsIdempotent() throws MalformedURLException {
// Then
assertThat(watcher.closeCount.get()).isEqualTo(1);
}

@Test
void closeEventWithExceptionIsIdempotentWithReconnecting() throws MalformedURLException {
// Given
final WatcherAdapter<HasMetadata> watcher = new WatcherAdapter<HasMetadata>() {
@Override
public boolean reconnecting() {
return true;
}
};
final WatchManager<HasMetadata> awm = withDefaultWatchManager(watcher);
// When
for (int it = 0; it < 10; it++) {
awm.close(new WatcherException("Mock"));
}
// Then
assertThat(watcher.closeCount.get()).isEqualTo(1);
}

@Test
@DisplayName("closeWebSocket, closes web socket with 1000 code (Normal Closure)")
Expand Down

0 comments on commit a9366ef

Please sign in to comment.