GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Close Channel when connect is cancelled during resolution by Gimini-3 · Pull Request #17321 · netty/netty

Conversation

@Gimini-3

@Gimini-3 Gimini-3 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Gimini-3 and others added 2 commits August 25, 2026 01:49
@Gimini-3
Close Channel when connect is cancelled during resolution
2b99745
Install the close-on-failure listener before asynchronous address resolution starts. Ignore late resolver completion after cancellation and avoid resolving addresses when cancellation wins the registration race.
@normanmaurer
Merge branch '4.2' into fix-bootstrap-resolve-cancellation
02a8261
@normanmaurer

normanmaurer commented Aug 26, 2026

Copy link
Copy Markdown
Member

@Gimini-3 I think it would be better to call setUncancellable(.....) on the promise and don't use try*.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Gimini-3
Make Bootstrap connect uncancellable during resolution
4e4060e
Mark the connect promise uncancellable before address resolution starts and use strict promise completion methods. Keep cancellation before registration supported and covered by tests.
@Gimini-3

Gimini-3 commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

@normanmaurer Thanks, updated. The promise is now marked uncancellable before address resolution starts, and the try* calls and late isDone() guard have been removed. Cancellation that wins before registration still closes the Channel and skips resolution. I also updated the tests to cover both boundaries; ./mvnw -pl transport test passes (397 tests, 9 skipped).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

normanmaurer
normanmaurer reviewed Aug 26, 2026
View reviewed changes
Comment thread transport/src/main/java/io/netty/bootstrap/Bootstrap.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

normanmaurer
normanmaurer reviewed Aug 26, 2026
View reviewed changes
Comment thread transport/src/main/java/io/netty/bootstrap/Bootstrap.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

normanmaurer
normanmaurer requested changes Aug 26, 2026
View reviewed changes
Gimini-3 and others added 2 commits August 26, 2026 22:54
@Gimini-3
Restore existing Bootstrap failure handling
e53a1ba
@normanmaurer
Merge branch '4.2' into fix-bootstrap-resolve-cancellation
010a401
normanmaurer
normanmaurer approved these changes Aug 27, 2026
View reviewed changes
@normanmaurer normanmaurer modified the milestones: 4.1.138.Final, 4.2.18.Final Aug 27, 2026
@normanmaurer normanmaurer added needs-cherry-pick-4.1 This PR should be cherry-picked to 4.1 once merged. needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. labels Aug 27, 2026
@normanmaurer
normanmaurer enabled auto-merge (squash) August 27, 2026 06:26
@normanmaurer normanmaurer closed this Aug 27, 2026
auto-merge was automatically disabled August 27, 2026 06:26

Pull request was closed

@normanmaurer normanmaurer reopened this Aug 27, 2026
@normanmaurer

normanmaurer commented Aug 27, 2026

Copy link
Copy Markdown
Member

@Gimini-3 hmm I think this needs some more thoughts... as the unit test failures show as with the current changes cancellation is not possible at all. So maybe your original changes were better. WDYT ?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Gimini-3

Gimini-3 commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

I agree that the original approach is better here. setUncancellable() changes the semantics of the entire connect operation and prevents cancellation even after address resolution, as SocketConnectionAttemptTest shows.
The original approach preserves connect cancellation by installing CLOSE_ON_FAILURE before resolution, returning when the connect promise is already done, and safely ignoring late resolver completion without cancelling the resolver future. Would you prefer that I restore this approach?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@normanmaurer

normanmaurer commented Aug 27, 2026

Copy link
Copy Markdown
Member

Yes

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Gimini-3
Restore connect cancellation during resolution
b5f9f40
@Gimini-3

Gimini-3 commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, restored the original approach in b5f9f40. The relevant tests pass locally, and CI is running.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

normanmaurer
normanmaurer reviewed Aug 27, 2026
View reviewed changes
Comment thread transport/src/main/java/io/netty/bootstrap/Bootstrap.java Outdated

// Wait until the name resolution is finished.
resolveFuture.addListener((FutureListener<SocketAddress>) future -> {
if (promise.isDone()) {

@normanmaurer normanmaurer Aug 27, 2026

Copy link
Copy Markdown
Member

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 this correct ? This means we would also not try to close the channel in this of a failure.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@Gimini-3 Gimini-3 Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

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.

Good point. Updated in 306143a1d7 to handle resolver failures first, so the Channel is always closed on failure. A completed promise now only skips doConnect(...) after successful resolution.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
normanmaurer
normanmaurer requested changes Aug 27, 2026
View reviewed changes
@Gimini-3
Handle resolver failure before connect completion
306143a
@testlens-app

testlens-app Bot commented Aug 28, 2026

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: 306143a
▶️ Tests: 450798 executed
⚪️ Checks: 18/18 completed


Learn more about TestLens at testlens.app/docs.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

normanmaurer
normanmaurer approved these changes Aug 28, 2026
View reviewed changes
@normanmaurer
normanmaurer merged commit 66af5f8 into netty:4.2 Aug 28, 2026
19 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@netty-project-bot

netty-project-bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Could not create auto-port PR.
Got conflicts when cherry-picking onto 4.1.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@netty-project-bot

netty-project-bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Could not create auto-port PR.
Got conflicts when cherry-picking onto 5.0.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@normanmaurer

normanmaurer commented Aug 28, 2026

Copy link
Copy Markdown
Member

PR for 4.1 #17349

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

normanmaurer added a commit that referenced this pull request Aug 28, 2026
@normanmaurer @Gimini-3
Close Channel when connect is cancelled during resolution (#17321) (#…
6098d84
…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]>
@lhotari lhotari mentioned this pull request Sep 10, 2026
[fix][sec] Upgrade Netty to 4.2.18 to address several CVEs and bugs apache/pulsar#26514
Merged
2 of 11 tasks
@normanmaurer normanmaurer mentioned this pull request Oct 1, 2026
child5 #17695
Closed
@normanmaurer normanmaurer removed needs-cherry-pick-4.1 This PR should be cherry-picked to 4.1 once merged. needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. labels Oct 16, 2026
lltopk pushed a commit to lltopk/netty that referenced this pull request Oct 24, 2026
@normanmaurer @Gimini-3 @lltopk
Close Channel when connect is cancelled during resolution (netty#17321)…
d5f6a8e
… (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]>
@normanmaurer normanmaurer mentioned this pull request Oct 26, 2026
crisp nova cceda091 #18109
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@normanmaurer normanmaurer normanmaurer approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

4.2.18.Final

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@Gimini-3 @normanmaurer @netty-project-bot
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.