Repository navigation
Conversation
Ruby 3.0 began to set O_NONBLOCK by default for all IO, to allow more IO types to enlist in the new IO/fiber scheduling. JRuby has not previously defaulted to nonblock, but all IO operations against nonblock-compatible channels does use nonblocking semantics, so all we really need to align with CRuby is to just set them non-blocking at the NIO level on creation. We can only do this when the underlying channel supports nonblocking semantics, but this commit attempts to set such channels up properly. Part of scheduler work in jruby#7459 and related issues.
In jruby#9886 a user reported that because of our locking of a selectable channels blockingLock while calling select, any blocking operation against that channel would prevent other operations from happening. In the case of a socket, which can both read and write concurrently, this limits functionality. The base problem is our need to set a blocking socket to nonblocking for the duration of the select and then safely restore it to blocking afterwards. If the socket were always nonblocking, no lock would need to be acquired because the blocking state would not need to be changed. The PR in jruby#7466 makes an attempt to mark selectable channels as nonblocking at create time, matching CRuby 3.0 behavior and opening up the possibility of avoiding the lock. That is implemented in this patch, which only acquires the lock if the blocking state needs to be reconfigured. This appears to fix the example from jruby#9886. It depends upon the nonblocking changes in jruby#7466.
|
Good experiment to try! |
IO#reopen calls setFD(null), which made updateBlockingFromFD throw a NullPointerException (TestIO#test_reopen_nonascii, reopen $stdout spec in spec:regression).
…ng sockets With sockets nonblocking at creation, BasicSocket#recv returned nil for TCP and "" for UDP, and UDPSocket#recvfrom raised ECONNRESET, whenever no data was ready yet. Wait for the channel to become readable and retry instead.
9c48a97 to
943b8ca
Compare
|
Update: the socket-only split didn't help. CI failed exactly the same tests as #9905 (master is green), so the
Those were the only failures on #9905, so if this run goes green the two commits can be pulled into #9905 as is. I couldn't build locally, so this CI run is also the first compile. |
|
Remaining failures appear to all ve EAGAIN from popen+read during specs on Windows, which has many peculiarities in its version of the IO subsystem. That's likely almost all one fix. |
On the Java-process popen path (used on Windows) the pipe channels are FileChannels or stream wrappers. Marking them nonblock only enabled PosixShim's emulation, which returns EAGAIN for pipes forever. setFD already syncs the flag for selectable channels.
|
Pushed a quick try for the Windows popen failures (b68db99, untested since I don't have Windows): it drops the two That path is only taken for Java-process popen (Windows), where the pipe channels are a This is Claude quick fix btw, as I mentioned I don't even have windows |
|
Restarted the tests, let's see how it goes. |
|
Looks like intermittent connection errors |
|
@route Yeah Maven Central has been having trouble lately. The good news is that you seem to have found all the fixes needed for this! |
|
Consider this for 10.1.4.0. Merge immediately after 10.1.3.0 to let it bake. |
Experiment for #9886: a socket-only subset of #7466 combined with #9905, to see how much of CI breaks when only sockets are set nonblocking at creation.
blockingLockonly when the channel is still blocking).initSocket,UNIXSocket,accept,TCPSocketconnect) and theOpenFilenonblock sync.RubyIOparts of Default to nonblocking whenever possible #7466 (initializeCommon,popen), so pipes, files and other IO keep their current blocking mode.Expected breakage is limited to socket paths that read or write the channel without waiting, e.g.
BasicSocket#recv(doRead), UDPreceive/send, and possibly jruby-openssl. If this subset turns out manageable, it could land before the rest of #7466.