Skip to content

Commit

Permalink
fix: clancel futures during failure (#91)
Browse files Browse the repository at this point in the history
resolves #85
  • Loading branch information
jeremylong authored Nov 24, 2023
1 parent 2cc6b70 commit 69ab87c
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,8 @@ private Future<RateLimitedCall> callApi(int clientIndex, int startIndex) throws
}

@Override
public void close() throws Exception {
if (clients != null) {
for (RateLimitedClient client : clients) {
client.close();
}
clients = null;
}
public void close() {
indexesToRetrieve.clear();
if (futures.size() > 0) {
for (Future<RateLimitedCall> future : futures) {
if (!future.isDone()) {
Expand All @@ -275,6 +270,16 @@ public void close() throws Exception {
}
futures.clear();
}
if (clients != null) {
for (RateLimitedClient client : clients) {
try {
client.close();
} catch (Exception ex) {
LOG.debug("Error closing client during `close`", ex);
}
}
clients = null;
}
}

@Override
Expand Down Expand Up @@ -342,13 +347,15 @@ public Collection<DefCveItem> next() {
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
close();
throw new NvdApiException(e);
} catch (ExecutionException e) {
// in rare cases we get an error from the NVD - log the error and only fail if we retry too many times
LOG.debug("Error retrieving the NVD data", e);
if (hasNext()) {
return next();
}
close();
return null;
}
}
Expand Down

0 comments on commit 69ab87c

Please sign in to comment.