Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ML] Release OpAddEntry.data when entry is copied and discarded #10773

Merged

Conversation

lhotari
Copy link
Member

@lhotari lhotari commented Jun 1, 2021

Fixes #10738

Motivation

There's a ByteBuf leak that happens in ledger rollover. The repro case in #10738 reproduces some Netty ByteBuf leaks that are detected by the Netty Leak detector.

Modifications

Release OpAddEntry.data when the original entry is copied and discarded

Additional Context

This PR was split out of PR #10755 which was closed without merging.

@lhotari lhotari self-assigned this Jun 1, 2021
@lhotari lhotari added this to the 2.8.0 milestone Jun 1, 2021
@lhotari lhotari added the type/bug The PR fixed a bug or issue reported a bug label Jun 1, 2021
@@ -1504,6 +1504,8 @@ public synchronized void updateLedgersIdsComplete(Stat stat) {
if (existsOp.ledger != null) {
existsOp.close();
existsOp = OpAddEntry.create(existsOp.ml, existsOp.data, existsOp.getNumberOfMessages(), existsOp.callback, existsOp.ctx);
// release the extra retain
ReferenceCountUtil.release(existsOp.data);
Copy link
Member

Choose a reason for hiding this comment

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

Just one question, doesn't existsOp.close release the reference? Or can you clarify (potentially comment in the code) why do we need to release extra retain here?

Copy link
Member Author

@lhotari lhotari Jun 1, 2021

Choose a reason for hiding this comment

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

Just one question, doesn't existsOp.close release the reference?

No it doesn't.

why do we need to release extra retain here?

OpAddEntry.create will call .retain , that's the extra retain. I already tried to clarify that in the comment in the code. Does it need more clarification?

Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM, just add more context here. We can safe to release the buffer here because we closed the old OpAddEntry, if the OpAddEntry in the closed state, even if the addComplete been called, will not use the buffer again.

        if (!STATE_UPDATER.compareAndSet(OpAddEntry.this, State.INITIATED, State.COMPLETED)) {
            log.warn("[{}] The add op is terminal legacy callback for entry {}-{} adding.", ml.getName(), lh.getId(), entryId);
            OpAddEntry.this.recycle();
            return;
        }

@devinbost
Copy link
Contributor

Linking to #6054 for tracking

@@ -1504,6 +1504,8 @@ public synchronized void updateLedgersIdsComplete(Stat stat) {
if (existsOp.ledger != null) {
existsOp.close();
existsOp = OpAddEntry.create(existsOp.ml, existsOp.data, existsOp.getNumberOfMessages(), existsOp.callback, existsOp.ctx);
// release the extra retain
ReferenceCountUtil.release(existsOp.data);
Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM, just add more context here. We can safe to release the buffer here because we closed the old OpAddEntry, if the OpAddEntry in the closed state, even if the addComplete been called, will not use the buffer again.

        if (!STATE_UPDATER.compareAndSet(OpAddEntry.this, State.INITIATED, State.COMPLETED)) {
            log.warn("[{}] The add op is terminal legacy callback for entry {}-{} adding.", ml.getName(), lh.getId(), entryId);
            OpAddEntry.this.recycle();
            return;
        }

@codelipenghui codelipenghui merged commit 80e3034 into apache:master Jun 2, 2021
wangjialing218 pushed a commit to wangjialing218/pulsar that referenced this pull request Jun 2, 2021
)

Fixes apache#10738

### Motivation

There's a ByteBuf leak that happens in ledger rollover. The repro case in apache#10738 reproduces some Netty ByteBuf leaks that are detected by the Netty Leak detector.

### Modifications

Release `OpAddEntry.data` when the original entry is copied and discarded

### Additional Context

This PR was split out of PR apache#10755 which was closed without merging.
lhotari added a commit that referenced this pull request Jun 2, 2021
Fixes #10738

There's a ByteBuf leak that happens in ledger rollover. The repro case in #10738 reproduces some Netty ByteBuf leaks that are detected by the Netty Leak detector.

Release `OpAddEntry.data` when the original entry is copied and discarded

This PR was split out of PR #10755 which was closed without merging.
@lhotari lhotari added the cherry-picked/branch-2.7 Archived: 2.7 is end of life label Jun 2, 2021
lhotari added a commit that referenced this pull request Jun 2, 2021
Fixes #10738

There's a ByteBuf leak that happens in ledger rollover. The repro case in #10738 reproduces some Netty ByteBuf leaks that are detected by the Netty Leak detector.

Release `OpAddEntry.data` when the original entry is copied and discarded

This PR was split out of PR #10755 which was closed without merging.
eolivelli pushed a commit to datastax/pulsar that referenced this pull request Jun 7, 2021
)

Fixes apache#10738

There's a ByteBuf leak that happens in ledger rollover. The repro case in apache#10738 reproduces some Netty ByteBuf leaks that are detected by the Netty Leak detector.

Release `OpAddEntry.data` when the original entry is copied and discarded

This PR was split out of PR apache#10755 which was closed without merging.

(cherry picked from commit 121305f)
yangl pushed a commit to yangl/pulsar that referenced this pull request Jun 23, 2021
)

Fixes apache#10738

### Motivation

There's a ByteBuf leak that happens in ledger rollover. The repro case in apache#10738 reproduces some Netty ByteBuf leaks that are detected by the Netty Leak detector.

### Modifications

Release `OpAddEntry.data` when the original entry is copied and discarded

### Additional Context

This PR was split out of PR apache#10755 which was closed without merging.
bharanic-dev pushed a commit to bharanic-dev/pulsar that referenced this pull request Mar 18, 2022
)

Fixes apache#10738

### Motivation

There's a ByteBuf leak that happens in ledger rollover. The repro case in apache#10738 reproduces some Netty ByteBuf leaks that are detected by the Netty Leak detector.

### Modifications

Release `OpAddEntry.data` when the original entry is copied and discarded

### Additional Context

This PR was split out of PR apache#10755 which was closed without merging.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-picked/branch-2.7 Archived: 2.7 is end of life release/2.7.3 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.

Direct memory leaks in ledger rollover or when Bookkeeper is overloaded
5 participants