Skip to content

Commit 74e2e17

Browse files
committed
io_uring/net: avoid sending -ECONNABORTED on repeated connection requests
Since io_uring does nonblocking connect requests, if we do two repeated ones without having a listener, the second will get -ECONNABORTED rather than the expected -ECONNREFUSED. Treat -ECONNABORTED like a normal retry condition if we're nonblocking, if we haven't already seen it. Cc: [email protected] Fixes: 3fb1bd6 ("io_uring/net: handle -EINPROGRESS correct for IORING_OP_CONNECT") Link: axboe/liburing#828 Reported-by: Hui, Chunyang <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent d2acf78 commit 74e2e17

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

io_uring/net.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ struct io_connect {
4747
struct sockaddr __user *addr;
4848
int addr_len;
4949
bool in_progress;
50+
bool seen_econnaborted;
5051
};
5152

5253
struct io_sr_msg {
@@ -1424,7 +1425,7 @@ int io_connect_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
14241425

14251426
conn->addr = u64_to_user_ptr(READ_ONCE(sqe->addr));
14261427
conn->addr_len = READ_ONCE(sqe->addr2);
1427-
conn->in_progress = false;
1428+
conn->in_progress = conn->seen_econnaborted = false;
14281429
return 0;
14291430
}
14301431

@@ -1461,18 +1462,24 @@ int io_connect(struct io_kiocb *req, unsigned int issue_flags)
14611462

14621463
ret = __sys_connect_file(req->file, &io->address,
14631464
connect->addr_len, file_flags);
1464-
if ((ret == -EAGAIN || ret == -EINPROGRESS) && force_nonblock) {
1465+
if ((ret == -EAGAIN || ret == -EINPROGRESS || ret == -ECONNABORTED)
1466+
&& force_nonblock) {
14651467
if (ret == -EINPROGRESS) {
14661468
connect->in_progress = true;
1467-
} else {
1468-
if (req_has_async_data(req))
1469-
return -EAGAIN;
1470-
if (io_alloc_async_data(req)) {
1471-
ret = -ENOMEM;
1469+
return -EAGAIN;
1470+
}
1471+
if (ret == -ECONNABORTED) {
1472+
if (connect->seen_econnaborted)
14721473
goto out;
1473-
}
1474-
memcpy(req->async_data, &__io, sizeof(__io));
1474+
connect->seen_econnaborted = true;
1475+
}
1476+
if (req_has_async_data(req))
1477+
return -EAGAIN;
1478+
if (io_alloc_async_data(req)) {
1479+
ret = -ENOMEM;
1480+
goto out;
14751481
}
1482+
memcpy(req->async_data, &__io, sizeof(__io));
14761483
return -EAGAIN;
14771484
}
14781485
if (ret == -ERESTARTSYS)

0 commit comments

Comments
 (0)