Skip to content

Commit

Permalink
Allow to cancel connect() operations when using io_uring (#237)
Browse files Browse the repository at this point in the history
Motivation:

Whe using io_uring we can in fact cancel a connect() operation by just
closing the underyling fd.

Modifications:

Don't mark the promise as uncancellable before issue the non-blocking
connect() call Add comment to explain code

Result:

Related to netty/netty#13843 and
netty/netty#13849
  • Loading branch information
normanmaurer authored Feb 16, 2024
1 parent a951c59 commit dfc64bb
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,9 @@ void connectComplete(int res) {
@Override
public void connect(
final SocketAddress remoteAddress, final SocketAddress localAddress, final ChannelPromise promise) {
if (!promise.setUncancellable() || !ensureOpen(promise)) {
// Don't mark the connect promise as uncancellable as in fact we can cancel it as it is using
// non-blocking io.
if (promise.isDone() || !ensureOpen(promise)) {
return;
}

Expand Down Expand Up @@ -760,6 +762,8 @@ public void run() {
promise.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) {
// If the connect future is cancelled we also cancel the timeout and close the
// underlying socket.
if (future.isCancelled()) {
cancelConnectTimeoutFuture();
connectPromise = null;
Expand Down

0 comments on commit dfc64bb

Please sign in to comment.