From 0c9d699194aa5fabb2ab4a4341f295145df00e0f Mon Sep 17 00:00:00 2001 From: Aayush Atharva Date: Sat, 18 Jul 2026 10:08:52 +0000 Subject: [PATCH] Mirror Netty option-failure semantics in applyChannelOptions --- .../netty/channel/ChannelManager.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/client/src/main/java/org/asynchttpclient/netty/channel/ChannelManager.java b/client/src/main/java/org/asynchttpclient/netty/channel/ChannelManager.java index e71f3b5f6..1de943333 100755 --- a/client/src/main/java/org/asynchttpclient/netty/channel/ChannelManager.java +++ b/client/src/main/java/org/asynchttpclient/netty/channel/ChannelManager.java @@ -300,12 +300,24 @@ private static Map.Entry, Object>[] buildChannelOptions(AsyncHt * Applies the pre-resolved channel options to a freshly created channel. Invoked from the channel initializer * (once per connection, on the channel's event loop, before the channel is connected), mirroring what * {@link Bootstrap#option} would otherwise do but without the shared, synchronized options map. + *

+ * The per-option handling mirrors Netty's {@code AbstractBootstrap#setChannelOption}: an unknown option is + * warned about and skipped, and a failure to set an option is warned about and rethrown so the channel is + * closed rather than connecting with a half-applied configuration. */ @SuppressWarnings("unchecked") private void applyChannelOptions(Channel channel) { ChannelConfig channelConfig = channel.config(); for (Map.Entry, Object> option : channelOptions) { - channelConfig.setOption((ChannelOption) option.getKey(), option.getValue()); + ChannelOption key = (ChannelOption) option.getKey(); + try { + if (!channelConfig.setOption(key, option.getValue())) { + LOGGER.warn("Unknown channel option '{}' for channel '{}'", key, channel); + } + } catch (Throwable t) { + LOGGER.warn("Failed to set channel option '{}' with value '{}' for channel '{}'", key, option.getValue(), channel, t); + throw t; + } } }