-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[fix][client] Fix client side memory leak when call MessageImpl.create and fix imprecise client-side metrics: pendingMessagesUpDownCounter, pendingBytesUpDownCounter, latencyHistogram #22393
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch!
Is there any condition in which this was getting triggered from the public APIs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Just a minor comment: Will if (ReferenceCountUtil.refCnt(payload) > 0) {
ReferenceCountUtil.release(payload);
} be better? double release a ReferentCount Object will throw an exception, and |
@poorbarcode Please answer to this question. I'm wondering about the valid usages of this API. Is it used internally in Pulsar since this is an internal API? How did you run into the problem? |
Regarding issue 2 that was described in Motivation, it will happen if batch sending is enabled(without calling the API
So there is no memory leak because the UnpooledByteBuf will not cause issues even if it is eventually not being released. Note: If someone builds messages by |
A custom plugin for our company uses this API. |
I think it is ok. If it will be released twice, we need this error log to let us know something is not as expected. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerImpl.java
Outdated
Show resolved
Hide resolved
pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerImpl.java
Outdated
Show resolved
Hide resolved
|
pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerImpl.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. The current title of the PR isn't optimal since this does fix issues also in other cases and also fixes some glitches with the stats.
Renamed the title. |
…e and fix imprecise client-side metrics: pendingMessagesUpDownCounter, pendingBytesUpDownCounter, latencyHistogram (apache#22393) (cherry picked from commit 2469b97) (cherry picked from commit 14b6279)
…e and fix imprecise client-side metrics: pendingMessagesUpDownCounter, pendingBytesUpDownCounter, latencyHistogram (apache#22393) (cherry picked from commit 2469b97) (cherry picked from commit 14b6279)
…e and fix imprecise client-side metrics: pendingMessagesUpDownCounter, pendingBytesUpDownCounter, latencyHistogram (apache#22393) (cherry picked from commit 2469b97) (cherry picked from commit 14b6279)
…s SpotBugs failure - SpotBugs check failed since there was an unused field "msgSize" - remove the unused field in branch-2.11
…e and fix imprecise client-side metrics: pendingMessagesUpDownCounter, pendingBytesUpDownCounter, latencyHistogram (apache#22393) (cherry picked from commit 2469b97) (cherry picked from commit 14b6279)
…e and fix imprecise client-side metrics: pendingMessagesUpDownCounter, pendingBytesUpDownCounter, latencyHistogram (apache#22393) (cherry picked from commit 2469b97) (cherry picked from commit 14b6279)
…e and fix imprecise client-side metrics: pendingMessagesUpDownCounter, pendingBytesUpDownCounter, latencyHistogram (apache#22393) (cherry picked from commit 2469b97)
|
Motivation
Issue 1: logs is below[1]
ProducerBase.sendAsync(Message)
Message.payload
isnull
after callingMessage.release
.Issue 2:
ProducerBase.sendAsync(msg1)
ProducerBase.sendAsync(msg2)
msg2.payload
was retained again when callinginterceptor.onSendAcknowledgement
, leading to this payload not being released. This retention is unnecessary. See https://github.com/apache/pulsar/blob/master/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerImpl.java#L430[1]:
The scope that the issue affects
Regarding issue-2 that was described in Motivation, it will happen if batch sending is enabled(without calling the API
ProducerBase.sendAsync(Message)
). But it will not cause an OOM because all the message payload created by the public API will be built this way:ByteBuffer jdkBuffer = ByteBuffer.wrap( byte[] )
ByteBuf nettyByteBuf = Unpooled.wrappedBuffer(jdkBuffer)
So there is no memory leak because the UnpooledByteBuf will not cause issues even if it is eventually not being released.
Note: If someone builds messages by
public static MessageImpl<T> create(ByteBuf payload)
and enables batch-send, they will encounter issue 2, but we did not provide an API to send a message typedorg.apache.pulsar.client.api.Message
, so no worry about this. (Highlight)It only affects the users who useProducerImpl
orProducerBase
Modifications
pendingMessagesUpDownCounter
pendingBytesUpDownCounter
latencyHistogram
Documentation
doc
doc-required
doc-not-needed
doc-complete
Matching PR in forked repository
PR in forked repository: x