Skip to content

Commit

Permalink
io_uring/net: don't retry connect operation on EPOLLERR
Browse files Browse the repository at this point in the history
If a socket is shutdown before the connection completes, POLLERR is set
in the poll mask. However, connect ignores this as it doesn't know, and
attempts the connection again. This may lead to a bogus -ETIMEDOUT
result, where it should have noticed the POLLERR and just returned
-ECONNRESET instead.

Have the poll logic check for whether or not POLLERR is set in the mask,
and if so, mark the request as failed. Then connect can appropriately
fail the request rather than retry it.

Reported-by: Sergey Galas <[email protected]>
Cc: [email protected]
Link: axboe/liburing#1335
Fixes: 3fb1bd6 ("io_uring/net: handle -EINPROGRESS correct for IORING_OP_CONNECT")
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
axboe committed Jan 30, 2025
1 parent d1fdab8 commit 8c8492c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions io_uring/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -1710,6 +1710,11 @@ int io_connect(struct io_kiocb *req, unsigned int issue_flags)
int ret;
bool force_nonblock = issue_flags & IO_URING_F_NONBLOCK;

if (unlikely(req->flags & REQ_F_FAIL)) {
ret = -ECONNRESET;
goto out;
}

file_flags = force_nonblock ? O_NONBLOCK : 0;

ret = __sys_connect_file(req->file, &io->addr, connect->addr_len,
Expand Down
2 changes: 2 additions & 0 deletions io_uring/poll.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ static int io_poll_check_events(struct io_kiocb *req, struct io_tw_state *ts)
return IOU_POLL_REISSUE;
}
}
if (unlikely(req->cqe.res & EPOLLERR))
req_set_fail(req);
if (req->apoll_events & EPOLLONESHOT)
return IOU_POLL_DONE;

Expand Down

0 comments on commit 8c8492c

Please sign in to comment.