Skip to content

[fix][offload] Close all resources in BlobStoreBackedReadHandleImplV2.closeAsync#25296

Merged
Technoboy- merged 2 commits into
apache:masterfrom
iamsanjaymalakar:master
Mar 10, 2026
Merged

[fix][offload] Close all resources in BlobStoreBackedReadHandleImplV2.closeAsync#25296
Technoboy- merged 2 commits into
apache:masterfrom
iamsanjaymalakar:master

Conversation

@iamsanjaymalakar

@iamsanjaymalakar iamsanjaymalakar commented Mar 7, 2026

Copy link
Copy Markdown
Contributor

Motivation

BlobStoreBackedReadHandleImplV2#closeAsync() closes indices and dataStreams sequentially inside a single try/catch. If closing one resource throws, the method exits early and the remaining resources are never closed. This can leak file descriptors and leave resources open when offload read handles are closed.

Modifications

  • Update closeAsync() to attempt closing all OffloadIndexBlockV2 instances and all DataInputStreams.

  • Collect the first IOException and attach subsequent failures via suppressed exceptions.

  • Complete the returned CompletableFuture exceptionally if any close operation fails; otherwise mark the handle Closed and complete normally.

  • doc

  • doc-required

  • doc-not-needed

  • doc-complete

@github-actions

github-actions Bot commented Mar 7, 2026

Copy link
Copy Markdown

@iamsanjaymalakar Please add the following content to your PR description and select a checkbox:

- [ ] `doc` <!-- Your PR contains doc changes -->
- [ ] `doc-required` <!-- Your PR changes impact docs and you will update later -->
- [ ] `doc-not-needed` <!-- Your PR changes do not impact docs -->
- [ ] `doc-complete` <!-- Docs have been already added -->

@github-actions github-actions Bot added doc-not-needed Your PR changes do not impact docs and removed doc-label-missing labels Mar 7, 2026
@codelipenghui codelipenghui added this to the 4.2.0 milestone Mar 9, 2026
@codelipenghui codelipenghui added release/4.1.4 release/4.0.10 type/bug The PR fixed a bug or issue reported a bug labels Mar 9, 2026

@codelipenghui codelipenghui left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And could you please also add tests to cover the changes from this PR, which can confirm the issue can be reproduced and avoid regression in the future.

@iamsanjaymalakar

Copy link
Copy Markdown
Contributor Author

Thanks for the reviews! I addressed the feedback by making closeAsync() close all resources without early exit and ensuring the returned future is always completed (even on runtime exceptions). I didn’t add a test because resource-leak/file-lock tests tend to be nondeterministic and flaky across OS/CI environments.

@lhotari

lhotari commented Mar 9, 2026

Copy link
Copy Markdown
Member

Please run "Personal CI" to validate such changes on your side. You can run Pulsar CI in your personal fork by following these instructions: https://pulsar.apache.org/contribute/personal-ci/. It's free.
The benefit is that you have full control of CI and you won't need to wait for maintainers to approve the CI workflow run to get CI feedback.

@lhotari

lhotari commented Mar 9, 2026

Copy link
Copy Markdown
Member

One detail about BlobStoreBackedReadHandleImplV2 is that it's not used in Pulsar's production code.
The
org.apache.bookkeeper.mledger.LedgerOffloader#readOffloaded(long, org.apache.bookkeeper.mledger.proto.MLDataFormats.OffloadContext, java.util.Map<java.lang.String,java.lang.String>) method is not called from production code which would use BlobStoreBackedReadHandleImplV2.
This something that I noticed while fixing a flaky tests a while ago in #24331.
"PIP 76: Streaming Offload" hasn't been fully implemented.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 42.10526% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.61%. Comparing base (f83251a) to head (6f464c3).
⚠️ Report is 8 commits behind head on master.

Files with missing lines Patch % Lines
...d/jcloud/impl/BlobStoreBackedReadHandleImplV2.java 42.10% 10 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #25296      +/-   ##
============================================
- Coverage     72.80%   72.61%   -0.19%     
+ Complexity    34660    34198     -462     
============================================
  Files          1968     1968              
  Lines        155954   156134     +180     
  Branches      17766    17787      +21     
============================================
- Hits         113537   113383     -154     
- Misses        33447    33695     +248     
- Partials       8970     9056      +86     
Flag Coverage Δ
inttests 25.63% <ø> (-0.61%) ⬇️
systests 22.29% <ø> (-0.22%) ⬇️
unittests 73.59% <42.10%> (-0.18%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...d/jcloud/impl/BlobStoreBackedReadHandleImplV2.java 64.44% <42.10%> (-3.63%) ⬇️

... and 100 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Technoboy-
Technoboy- merged commit c83cafc into apache:master Mar 10, 2026
102 of 104 checks passed
lhotari pushed a commit that referenced this pull request Mar 10, 2026
lhotari pushed a commit that referenced this pull request Mar 10, 2026
ridhkapoor pushed a commit to datastax/pulsar that referenced this pull request Mar 13, 2026
….closeAsync (apache#25296)

(cherry picked from commit c83cafc)
(cherry picked from commit e190cb5)
ganesh-ctds pushed a commit to datastax/pulsar that referenced this pull request Mar 16, 2026
….closeAsync (apache#25296)

(cherry picked from commit c83cafc)
(cherry picked from commit e190cb5)
ridhkapoor pushed a commit to datastax/pulsar that referenced this pull request Mar 16, 2026
….closeAsync (apache#25296)

(cherry picked from commit c83cafc)
(cherry picked from commit e190cb5)
ridhkapoor pushed a commit to datastax/pulsar that referenced this pull request Mar 17, 2026
….closeAsync (apache#25296)

(cherry picked from commit c83cafc)
(cherry picked from commit e190cb5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-picked/branch-4.0 cherry-picked/branch-4.1 doc-not-needed Your PR changes do not impact docs release/4.0.10 release/4.1.4 type/bug The PR fixed a bug or issue reported a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants