Repository navigation
Close Channel when connect is cancelled during resolution - #17321
Conversation
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.
|
@Gimini-3 I think it would be better to call |
Mark the connect promise uncancellable before address resolution starts and use strict promise completion methods. Keep cancellation before registration supported and covered by tests.
|
@normanmaurer Thanks, updated. The promise is now marked uncancellable before address resolution starts, and the |
Pull request was closed
|
@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 ? |
|
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. |
|
Yes |
|
Thanks, restored the original approach in b5f9f40. The relevant tests pass locally, and CI is running. |
|
|
||
| // Wait until the name resolution is finished. | ||
| resolveFuture.addListener((FutureListener<SocketAddress>) future -> { | ||
| if (promise.isDone()) { |
There was a problem hiding this comment.
is this correct ? This means we would also not try to close the channel in this of a failure.
There was a problem hiding this comment.
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.
✅ All tests passed ✅🏷️ Commit: 306143a Learn more about TestLens at testlens.app/docs. |
|
Could not create auto-port PR. |
|
Could not create auto-port PR. |
|
PR for 4.1 #17349 |
…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]>
… (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]>
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 logsIllegalStateException: complete already.Modification:
tryFailure(...)for cancellation races.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.