Skip to content

Always poll_connect on Apple platforms in connect_timeout - #669

Draft
rootkiller6788 wants to merge 1 commit into
rust-lang:masterfrom
rootkiller6788:fix/connect-timeout-apple
Draft

Always poll_connect on Apple platforms in connect_timeout#669
rootkiller6788 wants to merge 1 commit into
rust-lang:masterfrom
rootkiller6788:fix/connect-timeout-apple

Conversation

@rootkiller6788

Copy link
Copy Markdown

Fixes #652.

On Apple platforms (macOS, iOS, tvOS, watchOS, visionOS) a non-blocking connect(2) can return success even though the connection is not yet established. Socket::connect_timeout currently treats Ok(()) from connect as an immediate success and returns early, skipping poll_connect. In that case the function returns Ok(()) while peer_addr()/getpeername still reports ENOTCONN.

This change skips the fast-path early return on Apple platforms so the function always falls through to poll_connect, which waits for the connection to actually complete (and surfaces the real error on failure).

Behaviour on non-Apple platforms is unchanged.

Reported by @BiagioFesta in #652 and confirmed by @Thomasdezeeuw.

On Apple platforms (macOS, iOS, tvOS, watchOS, visionOS) a non-blocking
connect(2) can return success even though the connection is not yet
established. Treating that as immediate success causes connect_timeout
to return Ok(()) while the socket is still unconnected.

Skip the fast-path early return on Apple platforms so the function
always falls through to poll_connect, which waits for the connection to
actually complete.

Fixes rust-lang#652.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

connect_timeout returns Ok(()) on macOS but socket is not connected

1 participant