-
-
Notifications
You must be signed in to change notification settings - Fork 15.9k
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
netty-codec: Manage read-flow explicitly in MessageAggregator #6604
netty-codec: Manage read-flow explicitly in MessageAggregator #6604
Conversation
2308374
to
75ac8df
Compare
Okay, I added a new |
75ac8df
to
8a0e852
Compare
Ping @Scottmitch, @normanmaurer. Please, let me know if there is anything you think could be improved here. |
|
||
protected MockMessageAggregator() { | ||
super(1024); | ||
} |
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.
please fix formatting
ReadCounter counter = new ReadCounter(); | ||
ByteBufHolder first = new DefaultByteBufHolder(Unpooled.wrappedBuffer("first".getBytes())); | ||
ByteBufHolder chunk = new DefaultByteBufHolder(Unpooled.wrappedBuffer("chunk".getBytes())); | ||
ByteBufHolder last = new DefaultByteBufHolder(Unpooled.wrappedBuffer("last".getBytes())); |
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.
use Unpooled.copiedBuffer(..., CharsetUtil.US_ASCII);
assertTrue(embedded.writeInbound(last)); | ||
|
||
assertEquals(3, counter.value); // 2 reads issued from MockMessageAggregator | ||
// 1 read issued from EmbeddedChannel constructor |
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.
fix formatting
assertEquals(3, counter.value); // 2 reads issued from MockMessageAggregator | ||
// 1 read issued from EmbeddedChannel constructor | ||
assertTrue(embedded.finish()); | ||
} |
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.
use embedded.readInbound()
and so train the read messages. Also assert its what you expect and ensure you release everything
import io.netty.channel.embedded.EmbeddedChannel; | ||
|
||
public class MessageAggregatorTest { | ||
static class ReadCounter extends ChannelOutboundHandlerAdapter { |
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.
private final
b908d09
to
ba22048
Compare
@normanmaurer thank a lot of the review The PR is updated! |
ba22048
to
d2d82e2
Compare
|
||
private static ByteBufHolder message(String string) { | ||
return new DefaultByteBufHolder( | ||
Unpooled.copiedBuffer(string.getBytes(CharsetUtil.US_ASCII))); |
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.
nit: Unpooled.copiedBuffer(string, CharsetUtil.US_ASCII);
No need to first convert to byte[] and then do the copy
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.
Sure! Just updated the PR.
d2d82e2
to
cc8cd3e
Compare
Cherry-picked as 4c77e7c into 4.1 |
Motivation:
MessageAggregator
doesn't manage the read-flow when auto-read is disabled, which may result in connection stalls.Modification:
Keep reading the channel if auto-read is disabled and the current message isn't yet fully aggregated.
Result:
Fixes #6583.