From 187a3e61e6f60544509702baf886f8cebcc34d5e Mon Sep 17 00:00:00 2001 From: Duane Griffin Date: Mon, 26 May 2025 01:39:42 +1200 Subject: [PATCH 1/3] gh-117208: handle EAGAIN in non-blocking connect When calling ``connect`` in non-blocking mode it fails with errno set to EINPROGRESS if the connection cannot be completed immediately. Except for UNIX domain sockets, on Linux, which fail with EAGAIN instead. Fix the conditional check in the socket connection code to account for this lovely little inconsistency. --- .../Library/2025-05-26-01-48-09.gh-issue-117208.mmFGDb.rst | 3 +++ Modules/socketmodule.c | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2025-05-26-01-48-09.gh-issue-117208.mmFGDb.rst diff --git a/Misc/NEWS.d/next/Library/2025-05-26-01-48-09.gh-issue-117208.mmFGDb.rst b/Misc/NEWS.d/next/Library/2025-05-26-01-48-09.gh-issue-117208.mmFGDb.rst new file mode 100644 index 00000000000000..2f0dd5a9a6482d --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-05-26-01-48-09.gh-issue-117208.mmFGDb.rst @@ -0,0 +1,3 @@ +Fix error handling for non-blocking ``connect`` calls which meant +:func:`socket.connect` was sometimes raising a :exc:`BlockingIOError` instead +of waiting when a connection could not be immediately completed. diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 92c9aa8b510dca..6cd00613ac8ea9 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -3671,7 +3671,8 @@ internal_connect(PySocketSockObject *s, struct sockaddr *addr, int addrlen, wait_connect = (s->sock_timeout != 0 && IS_SELECTABLE(s)); } else { - wait_connect = (s->sock_timeout > 0 && err == SOCK_INPROGRESS_ERR + wait_connect = (s->sock_timeout > 0 + && (err == EAGAIN || err == SOCK_INPROGRESS_ERR) && IS_SELECTABLE(s)); } From 276adaeb9602828a83b2cabed179ed96df5bb3b4 Mon Sep 17 00:00:00 2001 From: Duane Griffin Date: Mon, 26 May 2025 17:11:38 +1200 Subject: [PATCH 2/3] Fix reference target --- .../next/Library/2025-05-26-01-48-09.gh-issue-117208.mmFGDb.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2025-05-26-01-48-09.gh-issue-117208.mmFGDb.rst b/Misc/NEWS.d/next/Library/2025-05-26-01-48-09.gh-issue-117208.mmFGDb.rst index 2f0dd5a9a6482d..4a9a2c19ac5923 100644 --- a/Misc/NEWS.d/next/Library/2025-05-26-01-48-09.gh-issue-117208.mmFGDb.rst +++ b/Misc/NEWS.d/next/Library/2025-05-26-01-48-09.gh-issue-117208.mmFGDb.rst @@ -1,3 +1,3 @@ Fix error handling for non-blocking ``connect`` calls which meant -:func:`socket.connect` was sometimes raising a :exc:`BlockingIOError` instead +:meth:`socket.connect` was sometimes raising a :exc:`BlockingIOError` instead of waiting when a connection could not be immediately completed. From 9ff2d077deaacfea30f0abf9d770de4a37f80398 Mon Sep 17 00:00:00 2001 From: Duane Griffin Date: Mon, 26 May 2025 17:15:54 +1200 Subject: [PATCH 3/3] Try again to correct the reference in the NEWS entry --- .../Library/2025-05-26-01-48-09.gh-issue-117208.mmFGDb.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS.d/next/Library/2025-05-26-01-48-09.gh-issue-117208.mmFGDb.rst b/Misc/NEWS.d/next/Library/2025-05-26-01-48-09.gh-issue-117208.mmFGDb.rst index 4a9a2c19ac5923..029d3ae7c44ec9 100644 --- a/Misc/NEWS.d/next/Library/2025-05-26-01-48-09.gh-issue-117208.mmFGDb.rst +++ b/Misc/NEWS.d/next/Library/2025-05-26-01-48-09.gh-issue-117208.mmFGDb.rst @@ -1,3 +1,3 @@ Fix error handling for non-blocking ``connect`` calls which meant -:meth:`socket.connect` was sometimes raising a :exc:`BlockingIOError` instead -of waiting when a connection could not be immediately completed. +:meth:`socket.socket.connect` was sometimes raising a :exc:`BlockingIOError` +instead of waiting when a connection could not be immediately completed.