Skip to content

Commit

Permalink
fix: prevent memory leak (#189)
Browse files Browse the repository at this point in the history
resolves #188
  • Loading branch information
jeremylong authored Jul 9, 2024
1 parent 2cb06fd commit 4f66082
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,14 @@ public boolean hasNext() {
*/
@Override
public Collection<DefCveItem> next() {
return _next(0);
}

private Collection<DefCveItem> _next(int retryCount) {
if (retryCount > 5) {
throw new NvdApiRetryExceededException(
"NVD Update Failed: attempted to retrieve data from the NVD unsuccessfully five times.");
}
if (firstCall) {
futures.add(callApi(0, 0));
}
Expand All @@ -335,7 +343,7 @@ public Collection<DefCveItem> next() {
call = getCompletedFuture();
if (call == null) {
if (hasNext()) {
return next();
return _next(retryCount + 1);
}
} else {
SimpleHttpResponse response = call.getResponse();
Expand All @@ -354,7 +362,7 @@ public Collection<DefCveItem> next() {
} catch (JsonProcessingException e) {
LOG.debug("Error processing NVD data", e);
// Re-try on what might be temporarily streaming errors
return next();
return _next(retryCount + 1);
}
this.totalAvailable = current.getTotalResults();
lastUpdated = findLastUpdated(lastUpdated, current.getVulnerabilities());
Expand All @@ -381,7 +389,7 @@ public Collection<DefCveItem> next() {
// 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();
return _next(retryCount + 1);
}
close();
}
Expand Down

0 comments on commit 4f66082

Please sign in to comment.