Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add warning for IO.select with single argument. #9061

Closed
ioquatix opened this issue Nov 16, 2020 · 2 comments · Fixed by #10075
Closed

Add warning for IO.select with single argument. #9061

ioquatix opened this issue Nov 16, 2020 · 2 comments · Fixed by #10075

Comments

@ioquatix
Copy link

ioquatix commented Nov 16, 2020

Maybe this is a crazy idea, but it would be awesome if we could automatically rewrite the following:

IO.select([io], [], [], timeout)
# becomes
io.wait_readable(timeout)
IO.select([], [io], [], timeout)
# becomes
io.wait_writable(timeout)

And finally, every other usage of IO.select becomes warning/error.

Because it is very hard to make it compatible with Ruby 3 scheduler.

It could be disabled by default if it's too inconvenient.

@ioquatix
Copy link
Author

Here is an example PR: redis/redis-rb#960

koic added a commit to koic/rubocop that referenced this issue Sep 11, 2021
…er` cop

Fixes rubocop#9061.

This PR adds new `Lint/IncompatibleIoSelectWithFiberScheduler` cop.
It checks for `IO.select` that is incompatible with Fiber Scheduler since Ruby 3.0.

```ruby
# bad
IO.select([io], [], [], timeout)

# good
io.wait_readable(timeout)

# bad
IO.select([], [io], [], timeout)

# good
io.wait_writable(timeout)
```

Ref: `Fiber Scheduler` section of https://www.ruby-lang.org/en/news/2020/12/25/ruby-3-0-0-released/

This PR will make it possible to detect proven cases with redis/redis-rb#960.
bbatsov pushed a commit that referenced this issue Sep 12, 2021
Fixes #9061.

This PR adds new `Lint/IncompatibleIoSelectWithFiberScheduler` cop.
It checks for `IO.select` that is incompatible with Fiber Scheduler since Ruby 3.0.

```ruby
# bad
IO.select([io], [], [], timeout)

# good
io.wait_readable(timeout)

# bad
IO.select([], [io], [], timeout)

# good
io.wait_writable(timeout)
```

Ref: `Fiber Scheduler` section of https://www.ruby-lang.org/en/news/2020/12/25/ruby-3-0-0-released/

This PR will make it possible to detect proven cases with redis/redis-rb#960.
@ioquatix
Copy link
Author

This is amazing thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants