Skip to content

Close Channel when connect is cancelled during resolution (#17321) - #17349

Merged
normanmaurer merged 2 commits into
4.1from
close41
Aug 28, 2026
Merged

normanmaurer merged 2 commits into
4.1from
close41

Conversation

@normanmaurer

Copy link
Copy Markdown
Member

Motivation:

Bootstrap.connect(...) creates and registers a Channel before
asynchronous address resolution. If the connect future is cancelled
while resolution is pending, the Channel remains open until resolution
completes. A late resolver failure also attempts to fail the cancelled
promise and logs IllegalStateException: complete already.

Modification:

  • Install the close-on-failure listener before address resolution starts
    so cancellation closes the registered Channel.
  • Skip address resolution when cancellation wins the registration race.
  • Ignore late resolver completion after the connect promise is done and
    use tryFailure(...) for cancellation races.
  • Keep the resolver future active so shared in-flight resolutions are
    not cancelled.
  • Add regression tests for cancellation during resolution with a real
    NIO Channel and before delayed registration completes.

Result:

Cancelling a Bootstrap connect closes its Channel while address
resolution is pending, late resolver completion no longer tries to
complete a cancelled promise, and delayed registration does not start
unnecessary resolution.


Co-authored-by: Norman Maurer [email protected]

Motivation:

`Bootstrap.connect(...)` creates and registers a Channel before
asynchronous address resolution. If the connect future is cancelled
while resolution is pending, the Channel remains open until resolution
completes. A late resolver failure also attempts to fail the cancelled
promise and logs `IllegalStateException: complete already`.

Modification:

- Install the close-on-failure listener before address resolution starts
so cancellation closes the registered Channel.
- Skip address resolution when cancellation wins the registration race.
- Ignore late resolver completion after the connect promise is done and
use `tryFailure(...)` for cancellation races.
- Keep the resolver future active so shared in-flight resolutions are
not cancelled.
- Add regression tests for cancellation during resolution with a real
NIO Channel and before delayed registration completes.

Result:

Cancelling a Bootstrap connect closes its Channel while address
resolution is pending, late resolver completion no longer tries to
complete a cancelled promise, and delayed registration does not start
unnecessary resolution.

---------

Co-authored-by: Norman Maurer <[email protected]>
@normanmaurer
normanmaurer merged commit 6098d84 into 4.1 Aug 28, 2026
18 checks passed
@normanmaurer
normanmaurer deleted the close41 branch August 28, 2026 09:17
lltopk pushed a commit to lltopk/netty that referenced this pull request Oct 24, 2026
… (netty#17349)

Motivation:

`Bootstrap.connect(...)` creates and registers a Channel before
asynchronous address resolution. If the connect future is cancelled
while resolution is pending, the Channel remains open until resolution
completes. A late resolver failure also attempts to fail the cancelled
promise and logs `IllegalStateException: complete already`.

Modification:

- Install the close-on-failure listener before address resolution starts
so cancellation closes the registered Channel.
- Skip address resolution when cancellation wins the registration race.
- Ignore late resolver completion after the connect promise is done and
use `tryFailure(...)` for cancellation races.
- Keep the resolver future active so shared in-flight resolutions are
not cancelled.
- Add regression tests for cancellation during resolution with a real
NIO Channel and before delayed registration completes.

Result:

Cancelling a Bootstrap connect closes its Channel while address
resolution is pending, late resolver completion no longer tries to
complete a cancelled promise, and delayed registration does not start
unnecessary resolution.

---------

Co-authored-by: Norman Maurer <[email protected]>

---------

Co-authored-by: Gimin Kim <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants