Skip to content

Commit

Permalink
Decref CacheFileRegion after read is done not before (elastic#102848)
Browse files Browse the repository at this point in the history
The CacheFileRegion instance is decref before the read operation 
is executed, meaning that the SharedBytes.IO instance can return 
to the pool of free regions, being polled and written by another 
thread for another cache file region, before the first read is 
effectively completed (and will return incorrect bytes).
  • Loading branch information
tlrx committed Dec 8, 2023
1 parent 479fcef commit 1edcee8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/changelog/102848.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 102848
summary: Decref `SharedBytes.IO` after read is done not before
area: Snapshot/Restore
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ void populateAndRead(
final List<SparseFileTracker.Gap> gaps = tracker.waitForRange(
rangeToWrite,
rangeToRead,
ActionListener.runBefore(listener, resource::close).delegateFailureAndWrap((l, success) -> {
ActionListener.runAfter(listener, resource::close).delegateFailureAndWrap((l, success) -> {
var ioRef = io;
assert regionOwners.get(ioRef) == this;
final int start = Math.toIntExact(rangeToRead.start());
Expand Down

0 comments on commit 1edcee8

Please sign in to comment.