-
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] [broker] network package lost if enable haProxyProtocolEnabled #21684
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.
Good catch.
pulsar-common/src/main/java/org/apache/pulsar/common/protocol/OptionalProxyProtocolDecoder.java
Outdated
Show resolved
Hide resolved
ctx.pipeline().addAfter(NAME, null, new HAProxyMessageDecoder()); | ||
ctx.pipeline().remove(this); | ||
} | ||
super.channelRead(ctx, buf); |
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.
It is better to remove the OptionalProxyProtocolDecoder
from the pipeline if result.state() == ProtocolDetectionState.INVALID
. Otherwise, if buffer.readableBytes() < 12
then the channelRead will block.
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.
Otherwise, if buffer.readableBytes() < 12 then the channelRead will block.
Since we can get the result ProtocolDetectionState.INVALID
, the value of buffer.readableBytes()
must larger or equals 12
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.
When we get the result ProtocolDetectionState.INVALID
, it proves the user is not using HAProxy, we should remove the OptionalProxyProtocolDecoder
from the pipeline and don't need to continue to accumulate bytes.
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.
When we get the result ProtocolDetectionState.INVALID, it proves the user is not using HAProxy, we should remove the OptionalProxyProtocolDecoder from the pipeline and don't need to continue to accumulate bytes.
The current implementation is most stable when it is uncertain how many times HaProxy Prototl Notation
will be received during the lifetime of a connection (such as repeated send due to an error).
The probability of receiving one package that is less than 12
bytes is extremely low, so it doesn't affect performance.
Otherwise, if buffer.readableBytes() < 12 then the channelRead will block.
PulsarCommand at least has 12
bytes: [frame length][cmd length][base cmd]
, it will not cause a stuck.
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.
PulsarCommand at least has 12 bytes: [frame length][cmd length][base cmd], it will not cause a stuck.
What if the last byte read was less than 12 due to network unpacking?
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.
Agree with you, fixed
pulsar-common/src/main/java/org/apache/pulsar/common/protocol/OptionalProxyProtocolDecoder.java
Outdated
Show resolved
Hide resolved
pulsar-common/src/main/java/org/apache/pulsar/common/protocol/OptionalProxyProtocolDecoder.java
Outdated
Show resolved
Hide resolved
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #21684 +/- ##
============================================
+ Coverage 73.29% 73.41% +0.11%
+ Complexity 32769 32764 -5
============================================
Files 1893 1893
Lines 140745 140766 +21
Branches 15503 15506 +3
============================================
+ Hits 103166 103344 +178
+ Misses 29498 29317 -181
- Partials 8081 8105 +24
Flags with carried forward coverage won't be shown. Click here to find out more.
|
if (result.state() == ProtocolDetectionState.NEEDS_MORE_DATA) { | ||
// Accumulate data if need more data to detect the protocol. | ||
if (cumulatedByteBuf == null) { | ||
cumulatedByteBuf = new CompositeByteBuf(ctx.alloc(), false, MIN_BYTES_SIZE_TO_DETECT_PROTOCOL, buf); |
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.
PulsarByteBufAllocator
have defined memory policies and OOM listener. and it's not recommended to use the constructor to build CompositeByteBuf
in it's doc.
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.
PulsarByteBufAllocator have defined memory policies and OOM listener.
Ah, it is the same object. see: https://github.com/apache/pulsar/blob/master/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java#L488
and it's not recommended to use the constructor to build CompositeByteBuf in it's doc.
Since these two recommended methods ByteBufAllocator.compositeBuffer()
and Unpooled.wrappedBuffer(ByteBuf...)
do not support the param maxNumComponents
, we create CompositeByteBuf
by constructor is better.
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.
yes, the same. Ok
…21684) Fixes #21557 ### Motivation There is a network package loss issue after enabling `haProxyProtocolEnabled`, which leads the error `Checksum failed on the broker` and `Adjusted frame length exceeds`, you can reproduce the issue by the test `testSlowNetwork`. ### Modifications Fix the bug. (cherry picked from commit 6e18874)
…21684) Fixes #21557 ### Motivation There is a network package loss issue after enabling `haProxyProtocolEnabled`, which leads the error `Checksum failed on the broker` and `Adjusted frame length exceeds`, you can reproduce the issue by the test `testSlowNetwork`. ### Modifications Fix the bug. (cherry picked from commit 6e18874)
…21684) Fixes #21557 ### Motivation There is a network package loss issue after enabling `haProxyProtocolEnabled`, which leads the error `Checksum failed on the broker` and `Adjusted frame length exceeds`, you can reproduce the issue by the test `testSlowNetwork`. ### Modifications Fix the bug. (cherry picked from commit 6e18874)
…pache#21684) Fixes apache#21557 ### Motivation There is a network package loss issue after enabling `haProxyProtocolEnabled`, which leads the error `Checksum failed on the broker` and `Adjusted frame length exceeds`, you can reproduce the issue by the test `testSlowNetwork`. ### Modifications Fix the bug. (cherry picked from commit 6e18874)
…pache#21684) Fixes apache#21557 ### Motivation There is a network package loss issue after enabling `haProxyProtocolEnabled`, which leads the error `Checksum failed on the broker` and `Adjusted frame length exceeds`, you can reproduce the issue by the test `testSlowNetwork`. ### Modifications Fix the bug. (cherry picked from commit 6e18874)
…pache#21684) Fixes apache#21557 There is a network package loss issue after enabling `haProxyProtocolEnabled`, which leads the error `Checksum failed on the broker` and `Adjusted frame length exceeds`, you can reproduce the issue by the test `testSlowNetwork`. Fix the bug. (cherry picked from commit 6e18874)
Fixes #21557
Motivation
There is a network package loss issue after enabling
haProxyProtocolEnabled
, which leads the errorChecksum failed on the broker
andAdjusted frame length exceeds
, you can reproduce the issue by the testtestSlowNetwork
. See: https://github.com/apache/pulsar/blob/master/pulsar-common/src/main/java/org/apache/pulsar/common/protocol/OptionalProxyProtocolDecoder.java#L43-L44Error logs:
Modifications
Fix the bug.
Documentation
doc
doc-required
doc-not-needed
doc-complete
Matching PR in forked repository
PR in forked repository: x