-
-
Notifications
You must be signed in to change notification settings - Fork 925
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
JRuby's native SortedSet
lies about adding an object
#5035
Comments
Thanks Chuck, wouth checking I'm hoping there isn't much concurrency ...
followed by :
|
Perhaps it's time we finally dumped the CRuby impl of set.rb and made a proper one that's concurrency-friendly and not based on Hash. |
@headius this is a bug with the set.rb rewrite (to .java) on master - hopefully not concurrency related |
Ah ok I see. I will try to help look into this on my journey home.
|
@kares Unfortunately I can't run it on any 9.1.x release because of issue 4920. That Fiber fix hasn't been part of any release yet. As for the If you have access to an OSX machine, the current code should run fine. |
And I'll add a comment here like I did in IRC. There is no concurrent access to this SortedSet. It is only ever accessed by the thread running the From my testing yesterday, what I see happening is that the superclass's hash is adding the value. That's why |
Thanks Chuck, I assumed there isn't much concurrency but wanted to double check. |
@kares Pull latest master and try again. Until I figure out my Let me know if you need anything else. |
all reproducing now - the issue relates to trying to implement a proper def <=>(other)
@fire_time <=> other.fire_time
end
def ==(other)
# need a more specific equivalence test since multiple timers could be
# scheduled to go off at exactly the same time
# @fire_time == other.fire_time &&
# @callback == other.callback &&
# @periodical == other.periodical?
object_id == other.object_id
end so for the underlying def <=>(other)
cmp = @fire_time <=> other.fire_time
cmp.zero? ? object_id <=> other.object_id : cmp
end this is a bug (regression) of not having proper MRI compat on master -> will either need to blindly follow set.rb's |
I will make your modification to my code for now. Do you plan to make the native Java SortedSet conform to the Ruby semantics? |
yep MRI compat first - will use your original
|
@kares I guess the two options here are to implement our own Set that matches MRI semantics (i.e. not wrap slightly-off Java sets) or add a linked list for insertion ordering. The latter would still be more efficient than a fully-wrapped Hash but the former would be the most efficient. We might also take this opportunity to implement direct addressing as added in Ruby 2.4, which we could them reapply to our Hash. |
Environment
Provide at least:
JRuby version (
jruby -v
) and command line (flags, JRUBY_OPTS, etc)jruby 9.2.0.0-SNAPSHOT (2.4.1) 2018-02-01 aa2ea83 Java HotSpot(TM) 64-Bit Server VM 25.144-b01 on 1.8.0_144-b01 +jit [darwin-x86_64]
Operating system and platform (e.g.
uname -a
)Darwin Charless-Air 16.7.0 Darwin Kernel Version 16.7.0: Mon Nov 13 21:56:25 PST 2017; root:xnu-3789.72.11~1/RELEASE_X86_64 x86_64
Other relevant info you may wish to add:
RUN
ulimit -n 2000
before following the directions to duplicate the error.Expected Behavior
Script should exit after about 60 seconds back to a command prompt.
Actual Behavior
The program hangs indefinitely. After diving into the guts of the issue, a
Timers
class that I wrote is the culprit. It usesSortedSet
to keep track of timers. At some point during execution, several timers that are supposedly added to the set are not actually recorded. I discovered this when asserting in my code that@timers.size == @timers.to_a.size
and having it fail. I tried to add a similar assert to the Java code but while it compiles it doesn't actually seem to work. Since not all timers fire, another check within my program prevents it from exiting, however the bug is caused by a flaw inSortedSet
.Here's how to reproduce the issue.
% git clone git@github.com:chuckremes/ruby-io.git
git checkout b2be9780d2272c6a2e178f48a74333193ea536b2
ulimit -n 2000
# give yourself a few more file descriptors than the 256 defaultruby echo_tcp.rb
The text was updated successfully, but these errors were encountered: