Skip to content

Ensure connectable sockets finish#9305

Merged
headius merged 4 commits intojruby:jruby-10.0from
headius:finish_connect_in_select
Mar 12, 2026
Merged

Ensure connectable sockets finish#9305
headius merged 4 commits intojruby:jruby-10.0from
headius:finish_connect_in_select

Conversation

@headius
Copy link
Copy Markdown
Member

@headius headius commented Mar 12, 2026

Blocking connect logic differs on JDK versus standard C sockets.

In C sockets, a nonblocking connect followed by a select is sufficient to finish connecting and be ready for IO.

In JDK sockets, a nonblocking connect followed by a select must still be finished (SocketChannel.finishConnect) to set up internal structures and move the socket out of its pending ("connection-pending"). The socket will not be usable for IO until this finish step has been performed.

The logic here modifies IO.select to check for pending connections after a select-for-write, and if necessary to finish the connect process.

Fixes #9304

Blocking connect logic differs on JDK versus standard C sockets.

In C sockets, a nonblocking connect followed by a select is
sufficient to finish connecting and be ready for IO.

In JDK sockets, a nonblocking connect followed by a select must
still be finished (SocketChannel.finishConnect) to set up
internal structures and move the socket out of its pending
("connection-pending"). The socket will not be usable for IO until
this finish step has been performed.

The logic here modifies IO.select to check for pending connections
after a select-for-write, and if necessary to finish the connect
process.

Fixes jruby#9304
@headius headius added this to the JRuby 10.0.5.0 milestone Mar 12, 2026
headius added 3 commits March 12, 2026 11:23
Socket connection may have been finished elsewhere, such as by
IO.select. If already connected, just return true.
@headius headius force-pushed the finish_connect_in_select branch from 2d491bf to 41a6fb7 Compare March 12, 2026 19:34
@headius headius merged commit 8392664 into jruby:jruby-10.0 Mar 12, 2026
84 checks passed
@headius headius deleted the finish_connect_in_select branch March 12, 2026 20:18
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.

1 participant