Repository navigation
[fix][client] Fix client side memory leak when call MessageImpl.create and fix imprecise client-side metrics: pendingMessagesUpDownCounter, pendingBytesUpDownCounter, latencyHistogram - #22393
Conversation
merlimat
left a comment
There was a problem hiding this comment.
Nice catch!
Is there any condition in which this was getting triggered from the public APIs?
|
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. |
lhotari
left a comment
There was a problem hiding this comment.
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)
|
|
| log.error("[{}] [{}] Payload is null when calling onSendComplete, which is not expected.", | ||
| topic, producerName); | ||
| } else { | ||
| ReferenceCountUtil.safeRelease(payload); |
There was a problem hiding this comment.
This slightly changes the order between releasing the payload and calling ProducerInterceptor#onSendAcknowledgement, I made quick fix in #22393.
There was a problem hiding this comment.
Thanks for fixing, ❤️
…e and fix imprecise client-side metrics: pendingMessagesUpDownCounter, pendingBytesUpDownCounter, latencyHistogram (apache#22393)
Motivation
Issue 1: logs is below[1]
ProducerBase.sendAsync(Message)Message.payloadisnullafter callingMessage.release.Issue 2:
ProducerBase.sendAsync(msg1)ProducerBase.sendAsync(msg2)msg2.payloadwas 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 useProducerImplorProducerBaseModifications
pendingMessagesUpDownCounterpendingBytesUpDownCounterlatencyHistogramDocumentation
docdoc-requireddoc-not-neededdoc-completeMatching PR in forked repository
PR in forked repository: x