Repository navigation
Make socket "accept" methods dont block fibers (Fiber::Scheduler support) - #9813
Conversation
|
Great to have other people also work on the fiber scheduler! Could we cut the tests down a bit?
#9813 (comment) (I'm not a maintainer so take my review with a grain of salt) |
|
@sampokuokkanen, really really thanks for your time reviewing this! I ran some mutation tests on the code, trying to find holes in my tests, but that increased the number of specs too much. I removed some tests and kept only the main/edge path specs. About the workaround, i removed the code assuming your fix on #9818. So, without your change, the JRuby some specs on async-grpc will keep failing sometimes, then we also need your PR merged (thanks for the fix!). |
|
Welcome! I'll add my review and work with @sampokuokkanen to confirm this is good to go. |
headius
left a comment
There was a problem hiding this comment.
Just minor things in the tests that I noticed. The functionality added looks correct and avoids the scheduler overhead entirely when not current.
The specs might have some room for de-duplication with a shared spec but the content looks good right now.
|
@headius Applied your suggestion. And thanks for the review. Also made a push to solve one ci shard that failed due to a race in a test I added. |
headius
left a comment
There was a problem hiding this comment.
The final result looks clean but the history is a bit of a mess due to added and removed tests, review changes, and conflict resolution. To clean that up I'm just going to squash merge.
In the future, consider amending commits that have review problems or dropping commits that are later removed in whole or part. git rebase -i <base branch> is your friend, allowing you to go back and revise or remove individual commits.
|
Nice my friend! Thanks for the instructions |

The accept (and sysaccept for servers) methods of ServerSocket, TCPServer and UNIXServer were blocking the fiber threads until some client connects, never calling the io_wait.
When a client in another fiber tries to connect on, using the same scheduler, it never run, blocking the thread permanently.
Now they try a nonblocking accept, and while nothing is pending, wait on scheduler io_wait without holding any lock.
The io_wait result is handled as in "rb_io_maybe_wait_readable", and the server closing interrupts a waiting fiber as in #9760. Without a scheduler, the extra cost is one FiberScheduler.current call.
It also fixes 3 existing bugs around these methods:
The new specs passes on MRI 3.4 and 4.0. This test
test/async/grpc/client.rbof async-grpc was hanging.But now it passes together with #9805 of @sampokuokkanen.