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
Make Http2MultiplexHandler construction require explicit distinction between server and client #12546
Conversation
…between server and client Motivation: Because Http2MultiplexHandler attempts to infer `isServer` from the channel type (`ServerChannel`), it can't be used in an `EmbeddedChannel` for HTTP server testing. Modification: Deprecate the old Http2MultiplexHandler constructors, and replace them with `forClient` and `forServer` factory methods, similar to `Http2FrameCodecBuilder`. Result: - `Http2MultiplexHandler` can be used in an EmbeddedChannel - construction is a bit more clear, as you can't pass an `upgradeHandler` to a server multiplexer anymore, where it would never be used anyway
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.
only one nit.. Looks great otherwise
codec-http2/src/main/java/io/netty/handler/codec/http2/Http2MultiplexHandler.java
Outdated
Show resolved
Hide resolved
…ltiplexHandler.java Co-authored-by: Norman Maurer <norman_maurer@apple.com>
*/ | ||
@Deprecated |
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.
is deprecation actually necessary? This change helps for small edge case (testing, with EmbeddedChannel only - but many use real channels for testing), otherwise current API is sufficient. It would force netty users onto new API for no practical gain.
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's not like they have to be removed in 4.x, but it seems weird to have both the factory and the constructor.
*/ | ||
@Deprecated |
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.
is deprecation actually necessary? This change helps for small edge case (testing, with EmbeddedChannel only - but many use real channels for testing), otherwise current API is sufficient. It would force netty users onto new API for no practical gain.
@yawkat also wondering if |
Yes it's a possible workaround, but it seems like a worse solution. |
It addresses the root cause - aims to solve testing problem by extending test code. And is alternative to patching 1 production codec with new API to sidestep the fact that test So for "clean" solution you should instead have
and add ctor to
I am pretty sure your test then passes with
If you want to fix the problem today w/o patching netty at all, then
Hope this explanation is helpful. |
Actually there is already a constructor that takes a |
Note that EmbeddedChannel is not used only for testing. And there are other byte-carrying channels too (including the ones introduced by this multiplex handler!), where adding the marker interface is not feasible. By the same reasoning, we could change I also don't see the downside to this change. It does not remove any methods. And the class is even |
@yawkat while I agree that the change is not "bad" I also think that there is no really "need / benefit" for the change. |
/cc @chrisvest @trustin thoughts ? |
Fair enough. We can always reconsider if someone else hits this in a situation where a workaround is harder. |
There are not many cases where a server-or-not check comes up. Making EmbeddedChannel behave more similar to other channels (by adding a server-sibling) is the better option, in my opinion. For Netty 5 we can add an isServer method to Channel so we no longer need to infer this information, but can just ask (and override if need be). |
I think there are a few problems with getting the "serverness" from the
channel in general (though not all apply here).
- it doesn't make sense for all channels, eg it doesn't for udp (or, well,
embedded channels)
- for channels where it makes some sense, it may still be useful to
customize on a per-handler basis. Eg why shouldn't a user be able to run a
http2 connection in reverse, with the tcp server acting as the http2
client? Maybe not terribly useful, but it's still an arbitrary restriction.
Right now, basically the only constraint a handler imposes on the user in
terms of where the handler can be used is the "direction" of the handler
(is it outbound or inbound). Relying on the channel for inferring
"serverness" would add another constraint.
- it's less convenient in the handler implementation to have to infer from
the channel, because you have to wait for handlerAdded (also limits
sharability). The http2 frame codec is another example for this, since it
already has the forClient and forServer versions. Adjusting that to infer
from the channel would be harder to implement.
- explicit factories that differ for client and server allow for different
parameter sets, which makes the api cleaner. This multiplex handler is a
good example of this: in its current version, even the server variant
accepts an upgradeHandler, even though it is only used by the client
variant. This is not ideal api design.
These are some reason why I don't like this channel inference approach
(though it's not a big issue in a limited case like this pr), and why I
don't think "formalizing" it through an explicit Channel.isServer (with the
implication that more handlers will do inference in the future) is a good
idea.
…On Tue, Jul 5, 2022, 22:39 Chris Vest ***@***.***> wrote:
There are not many cases where a server-or-not check comes up. Making
EmbeddedChannel behave more similar to other channels (by adding a
server-sibling) is the better option, in my opinion. For Netty 5 we can add
an isServer method to Channel so we no longer need to infer this
information, but can just ask (and override if need be).
—
Reply to this email directly, view it on GitHub
<#12546 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AASIZII24EMBAUBYJGRQKLLVSSMONANCNFSM52MFXPDQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@chrisvest @normanmaurer I've found another case where this check fails. When you get a SocketChannel from inetd or systemd with socket activation (either through |
Motivation:
Because Http2MultiplexHandler attempts to infer
isServer
from the channel type (ServerChannel
), it can't be used in anEmbeddedChannel
for HTTP server testing.Modification:
Deprecate the old Http2MultiplexHandler constructors, and replace them with
forClient
andforServer
factory methods, similar toHttp2FrameCodecBuilder
.Result:
Http2MultiplexHandler
can be used in an EmbeddedChannelupgradeHandler
to a server multiplexer anymore, where it would never be used anyway