-
-
Notifications
You must be signed in to change notification settings - Fork 104
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
Use Fiber.current
for current execution context. Fixes #501.
#502
Conversation
@eregon wdyt? |
I'm not sure what the best option is to resolve the failure - do we add |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're dropping old rubies (< 2.3) in RSpec 4.
What are your primary targets? Do you still plan to support old rubies with pre-4.0 RSpec?
Does it make sense for RSpec to remove ReentrantMutex and use Monitor?
Or is it the case that Monitor has that same bug with Fiber.yield
inside synchronize
, and we'd better keep ReentrantMutex
with what we'll end up doing in this PR that would work with any Ruby version? And the plan is to keep it until we drop support for Ruby 3.0?
@@ -1,3 +1,5 @@ | |||
require 'fiber' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I foresee that @JonRowe would say that requiring a dependency from stdlib is something that we try to avoid at all costs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we don't require things that developers need to require because it causes weird failures for developers. (e.g. RSpec will pass because we require it but it won't work in dev/production).
@mutex.lock if @owner != Fiber.current | ||
@owner = Fiber.current |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WDYT of
def current
defined?(Fiber.current) ? Fiber.current : Thread.current
end
and using it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's broken.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please elaborate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whenever some file would require 'fiber'
the behavior and what's stored here would switch and it'd be a total mess.
Also Thread.current
is not good enough if there is any non-root Fiber (any Fiber.new
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some file would require 'fiber' the behavior and what's stored here would switch and it'd be a total mess
For sure. I hope they don't do it dynamically when there are existing fibers and reentrant mutexes in action. Otherwise - do you see any issue?
Ok, let's put it another way. I couldn't find any mention of Fiber
in stdlib docs. Core docs claim that in order to user current
/transfer
/alive?
one has to require 'fiber'
.
Unlike it is with require 'rubygems'
or require 'date'
, require 'set'
etc no constants are loaded, and it's not a problem if we load it from RSpec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this not break in a more typical threaded solution? E.g. JRuby
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope they don't do it dynamically when there are existing fibers and reentrant mutexes in action.
I don't think it's advisable to take that risk/assumption, and anyway AFAIK there is no need.
My guess is that it compares loaded features to a clean process. It's a defensive measure to avoid loading anything explicitly, including |
I would suggest that if monitor worked, you should use it, but it's broken by the same bug. Ideally we fix this in 3.0.2 |
The change looks good to me. Unfortunately there is no way to get Using |
@eregon We don't require Rubygems as well, and even explicitly avoid loading them on CI. |
I think one way to avoid needing any stdlib here is to use |
I can try it out this week and report back |
I made a PR using |
I defer to @eregon thanks for your help here. |
No description provided.