Handle InterruptedException properly
InterruptedException should never be ignored.
Before, operation would have kept retrying even if thread is
interrupted. Now, set the current thread as interrupted, log a warning
and abort the operation.
Change-Id: I03b69dcea10ab4bb3ca23d38dfbf00264f4e2401
diff --git a/src/main/java/com/ericsson/gerrit/plugins/eventslog/sql/SQLStore.java b/src/main/java/com/ericsson/gerrit/plugins/eventslog/sql/SQLStore.java
index 8c89e0f..5997dfb 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/eventslog/sql/SQLStore.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/eventslog/sql/SQLStore.java
@@ -167,21 +167,25 @@
if (e.getCause() instanceof ConnectException
|| e.getMessage().contains("terminating connection")) {
done = false;
- retryIfAllowed(failedConnections);
+ try {
+ retryIfAllowed(failedConnections);
+ } catch (InterruptedException e1) {
+ log.warn("Cannot store ChangeEvent for: " + projectName.get()
+ + ": Interrupted");
+ Thread.currentThread().interrupt();
+ return;
+ }
failedConnections++;
}
}
}
}
- private void retryIfAllowed(int failedConnections) {
+ private void retryIfAllowed(int failedConnections)
+ throws InterruptedException {
if (failedConnections < maxTries - 1) {
log.info("Retrying store event");
- try {
- Thread.sleep(waitTime);
- } catch (InterruptedException e1) {
- return;
- }
+ Thread.sleep(waitTime);
} else {
log.error("Failed to store event " + maxTries + " times");
setOnline(false);