Skip to content

Restore Netty's channel-option failure semantics in ChannelManager - #2246

Closed
hyperxpro wants to merge 1 commit into
mainfrom
harden-channel-option-failure-handling
Closed

Restore Netty's channel-option failure semantics in ChannelManager#2246
hyperxpro wants to merge 1 commit into
mainfrom
harden-channel-option-failure-handling

Conversation

@hyperxpro

Copy link
Copy Markdown
Member

Summary

Follow-up to #2219. That PR stopped setting channel options on the shared
Bootstrap and instead applies them per-channel from AHC's channel initializer
via Channel.config().setOption(...) in ChannelManager.applyChannelOptions, to
avoid Netty's per-connect synchronized (options) copy in
AbstractBootstrap.newOptionsArray() (issue #2218).

The new applyChannelOptions called setOption directly, which silently dropped
the error-handling that Netty's AbstractBootstrap#setChannelOption provides.
Compared to the previous Bootstrap#option path this changed behaviour on the
error path only:

  • Unknown option key (setOption returns false): previously logged
    "Unknown channel option ..."; now completely silent — a mistyped entry in
    config.getChannelOptions() produces no warning.
  • setOption throws (bad value / unsupported on socket): previously logged
    "Failed to set channel option ..." and, with CLOSE_ON_SET_OPTION_FAILURE
    defaulting to true, failed the connect with the real cause. Now the throwable
    propagates out of initChannel, where ChannelInitializer logs a generic
    "Failed to initialize a channel" and closes it — so the connect fails with a
    masked cause and no option-specific diagnostic.

Fix

Mirror Netty's AbstractBootstrap#setChannelOption in applyChannelOptions:

  • warn and skip on an unknown option key (setOption returned false);
  • warn (naming the option + value) and rethrow on failure, preserving Netty's
    close-on-failure semantics so a channel never connects with a half-applied
    configuration.

Happy-path behaviour is unchanged. Only user-supplied config.getChannelOptions()
can hit these branches; the built-in defaults are all guarded to valid ranges.

Compiles clean on JDK 11 (./mvnw -pl client -am compile).

@hyperxpro
hyperxpro deleted the harden-channel-option-failure-handling branch July 18, 2026 10:25
@AsyncHttpClientAsyncHttpClient locked and limited conversation to collaborators Jul 18, 2026
@hyperxpro
hyperxpro restored the harden-channel-option-failure-handling branch July 18, 2026 10:25
@hyperxpro
hyperxpro deleted the harden-channel-option-failure-handling branch July 18, 2026 10:45
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@hyperxpro