Skip to content

Commit

Permalink
[Kernel] Fix a bug around closing partially opened resources
Browse files Browse the repository at this point in the history
## Description
Fix a bug in resource handling where we are always closing the resources which should be closed only when a failure occurs.

Currently, the code opens two resources, it maintains the opened resource list to close in case the function isn't successful in opening all the required resources. Resources in the maintained list should only be closed when an error occurs (it should be in the `catch` block not in `finally`)

## How was this patch tested?
Existing tests
  • Loading branch information
vkorukanti authored Sep 14, 2023
1 parent 36d460f commit e2633ae
Showing 1 changed file with 2 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,9 @@ private CloseableIterator<Tuple2<FileDataReadResult, Boolean>> getNextActionsIte
);
}
} catch (IOException ex) {
// Close the opened iterators to avoid resource leak
Utils.closeCloseablesSilently(iteratorsToClose);
throw new UncheckedIOException(ex);
} finally {
// We don't know if this is normal operation, or if `readJsonFiles` or
// `readParquetFiles` above have thrown an exception. Luckily, it doesn't matter:
// closing a closeable that is already closed is safe.
Utils.closeCloseables(iteratorsToClose);
}
}

Expand Down

0 comments on commit e2633ae

Please sign in to comment.