Skip to content

Commit

Permalink
Fix #3015: Log InterruptedException in debug when it is a nominal ter…
Browse files Browse the repository at this point in the history
…minating behavior
  • Loading branch information
hibnico authored and manusa committed Apr 28, 2021
1 parent b54d41f commit 0282631
Show file tree
Hide file tree
Showing 13 changed files with 19 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* Fix #2788: Support FIPS mode in kubernetes-client with BouncyCastleFipsProvider
* Fix #2910: Move crd-generator tests from kubernetes-itests to kubernetes-tests
* Fix #3005: Make it possible to select which CRD version is generated / improve output
* Fix #3015: Thread interruption in a nominal case (like closing the client) are now logged in debug

#### Dependency Upgrade
* Fix #2979: Update Kubernetes Model to v1.21.0
Expand Down
4 changes: 0 additions & 4 deletions doc/CHEATSHEET.md
Original file line number Diff line number Diff line change
Expand Up @@ -2066,10 +2066,6 @@ client.pods().inNamespace(namespace).watch(resourceVersion, new Watcher<Pod>() {
// Wait till watch gets closed
isWatchClosed.await();
} catch (InterruptedException interruptedException) {
logger.log(Level.INFO, "Thread Interrupted!");
Thread.currentThread().interrupt();
}
```
- Watching with `ListOptions` object:
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@ public final T createOrReplace(T... items) {
try {
return waitUntilCondition(Objects::nonNull, 1, TimeUnit.SECONDS);
} catch (InterruptedException interruptedException) {
interruptedException.printStackTrace();
LOG.warn("Interrupted while waiting for the resource to be created or replaced. Gracefully assuming the resource has not been created and doesn't exist. ({})", interruptedException.getMessage());
Thread.currentThread().interrupt();
}
return null;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ protected static boolean loop(Consumer<CountDownLatch> consumer, long periodInMi
countDownLatch.await();
return true;
} catch (InterruptedException e) {
LOGGER.debug("Loop thread interrupted", e);
LOGGER.debug("Loop thread interrupted: {}", e.getMessage());
Thread.currentThread().interrupt();
return false;
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private void processLoop() throws Exception {
try {
this.queue.pop(this.processFunc);
} catch (InterruptedException t) {
log.warn("DefaultController#processLoop got interrupted {}", t.getMessage(), t);
log.debug("DefaultController#processLoop got interrupted: {}", t.getMessage());
Thread.currentThread().interrupt();
return;
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private void startWatcher() {
try {
Thread.sleep(WATCH_RESTART_DELAY_MILLIS);
} catch (InterruptedException e) {
log.error("Reflector thread was interrupted");
log.debug("Reflector thread was interrupted: {}", e.getMessage());
Thread.currentThread().interrupt();
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import io.fabric8.kubernetes.client.KubernetesClientException;
import io.fabric8.kubernetes.client.ResourceHandler;
import okhttp3.OkHttpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.HttpURLConnection;
import java.util.Objects;
Expand All @@ -29,6 +31,7 @@
import java.util.function.UnaryOperator;

public class CreateOrReplaceHelper<T extends HasMetadata> {
private static final Logger LOG = LoggerFactory.getLogger(CreateOrReplaceHelper.class);
public static final int CREATE_OR_REPLACE_RETRIES = 3;
private final UnaryOperator<T> createTask;
private final UnaryOperator<T> replaceTask;
Expand Down Expand Up @@ -77,7 +80,8 @@ public static HasMetadata createOrReplaceItem(OkHttpClient client, Config config
try {
return h.waitUntilCondition(client, config, namespaceToUse, m, Objects::nonNull, 1, TimeUnit.SECONDS);
} catch (InterruptedException interruptedException) {
interruptedException.printStackTrace();
Thread.currentThread().interrupt();
LOG.warn("Interrupted waiting for item to be created or replaced. Gracefully assuming the resource hasn't been created and doesn't exist. ({})", interruptedException.getMessage());
}
return null;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void onDelete(Dummy pod, boolean deletedFinalStateUnknown) {
}
} catch (InterruptedException inEx) {
Thread.currentThread().interrupt();
logger.info("HAS_SYNCED_THREAD INTERRUPTED!");
logger.warn("HAS_SYNCED_THREAD interrupted: {}", inEx.getMessage());
}
});

Expand All @@ -93,7 +93,7 @@ public void onDelete(Dummy pod, boolean deletedFinalStateUnknown) {
TimeUnit.MINUTES.sleep(5);
} catch (InterruptedException interruptedException) {
Thread.currentThread().interrupt();
logger.info("interrupted: {}", interruptedException.getMessage());
logger.warn("interrupted: {}", interruptedException.getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static void main(String[] args) {
} catch (KubernetesClientException e) {
logger.error("Unable to create job", e);
} catch (InterruptedException interruptedException) {
logger.warn("Thread interrupted!");
logger.warn("Interrupted while waiting for the job to be ready: {}", interruptedException.getMessage());
Thread.currentThread().interrupt();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static void main(String[] args) {
execWatch.close();
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
ie.printStackTrace();
logger.warn("Interrupted while waiting for the exec: {}", ie.getMessage());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void onClose(WatcherException e) {
// Wait till watch gets closed
isWatchClosed.await();
} catch (InterruptedException interruptedException) {
logger.info( "Thread Interrupted!");
logger.warn("Interrupted while waiting for the watch to close: {}", interruptedException.getMessage());
Thread.currentThread().interrupt();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static void main(String[] args) {
logger.info("Closing port forward");
} catch (InterruptedException interruptedException) {
Thread.currentThread().interrupt();
interruptedException.printStackTrace();
logger.warn("Interrupted while waiting for the port forward to be ready: {}", interruptedException.getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void onClosed(WebSocket webSocket, int code, String reason) {
try {
executor.awaitTermination(1, TimeUnit.MINUTES);
} catch (InterruptedException e) {
logger.debug(e.getLocalizedMessage());
logger.debug("Interrupted waiting for the executor service to shutdown: {}", e.getMessage());
Thread.currentThread().interrupt();
}
watchEventListenerList.remove(this);
Expand All @@ -87,7 +87,7 @@ public void onFailure(WebSocket webSocket, Throwable t, Response response) {
try {
executor.awaitTermination(1, TimeUnit.MINUTES);
} catch (InterruptedException e) {
logger.debug(e.getLocalizedMessage());
logger.debug("Interrupted waiting for the executor service to shutdown: {}", e.getMessage());
Thread.currentThread().interrupt();
}
watchEventListenerList.remove(this);
Expand Down

0 comments on commit 0282631

Please sign in to comment.