Fix missing "source" field for UDP transport based messages (#5512) #5519
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes an issue that has been introduced with the big Netty 4.1
update in PR #4397.
In Netty 3.x we always passed a "MessageEvent" through the channel
pipeline and got the remote address from that object. Since this object
doesn't exist anymore in Netty 4.x, we only pass the message payload's
"ByteBuf" through the pipeline and rely on the "Channel#getRemoteAddress"
method to always return the remote address object.
The problem is that this does indeed work for TCP based channels but it
doesn't work for UDP based channels. For UDP channels the
"#getRemoteAddress()" method always returns "null".
This is probably due to the connection-less nature of UDP.
For UDP transports Netty only creates a single channel. For TCP transports
there is one channel per TCP connection
To fix this we need to get our hands on the remote address when we
create the "RawMessage" object at the very end of the Netty pipeline.
Since we only pass the message payload "ByteBuf" through the Netty
pipeline, we could previously reuse several classes for TCP and UDP
transports because they were basically the same.
For UDP transports we now need to carry the remote address through the
pipeline by using a "AddressedEnvelope" (available in Netty) that takes
a payload and a sender/receiver object.
That means we have to create a few UDP specific - or rather
"AddressedEnvelope" specific - pipeline handlers because the shared ones
only know how to handle "ByteBuf" messages.
This PR moves some shared code out of the "NettyTransport" class up to
"AbstractTcpTransport" and "UdpTransport" so we can customize the
pipeline for the two different payload types. It also creates new
message aggregation handlers for the "AddressedEnvelope" objects.
In the future we can probably refactor this to share some more code, but
for 3.0 I tried to change as few as possible. The TCP pipeline is
basically unchanged apart from the "AbstractTcpTransport" change.
Fixes #5264
Fixes #5293
(cherry picked from commit 375e618)