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 returns nil backtrace for living newborn threads, whereas MRI returns [] #4891

Closed
ivoanjo opened this Issue Dec 11, 2017 · 4 comments

Comments

Projects
None yet
2 participants
@ivoanjo
Contributor

ivoanjo commented Dec 11, 2017

Environment

  • JRuby: jruby 9.1.15.0 (2.3.3) 2017-12-07 929fde8 Java HotSpot(TM) 64-Bit Server VM 25.151-b12 on 1.8.0_151-b12 +jit [linux-x86_64]
  • Kernel: Linux u186024434db159d25c92 4.10.0-38-generic #42~16.04.1-Ubuntu SMP Tue Oct 10 16:32:20 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
  • Distro: Ubuntu 16.04.3 LTS

Expected Behavior

Example code:

puts RUBY_DESCRIPTION

puts Thread.new { sleep }.backtrace.inspect

Output on MRI 2.0 to 2.5 (this seems to have changed from 1.9, where it returned nil):

ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux]
[]

(This is of course a race and may sometimes yield non-empty results)

Actual Behavior

Output on JRuby:

jruby 9.1.15.0 (2.3.3) 2017-12-07 929fde8 Java HotSpot(TM) 64-Bit Server VM 25.151-b12 on 1.8.0_151-b12 +jit [linux-x86_64]
nil
@headius

This comment has been minimized.

Member

headius commented Dec 11, 2017

So the mismatch is that we return nil when there's no trace and MRI returns an empty array, yes?

@headius

This comment has been minimized.

Member

headius commented Dec 11, 2017

@ivoanjo I know this behavior is a little fiddly, but maybe you can come up with a spec?

@ivoanjo

This comment has been minimized.

Contributor

ivoanjo commented Dec 11, 2017

So the mismatch is that we return nil when there's no trace and MRI returns an empty array, yes?

Yeah, that's the behavior I'm seeing.

@ivoanjo I know this behavior is a little fiddly, but maybe you can come up with a spec?

May take a few days due to x-mas shopping, but will do 👍

@headius

This comment has been minimized.

Member

headius commented Dec 11, 2017

Looks like I broke something by making all cases return []:

     [exec]   1) Failure:
     [exec] TestThread#test_backtrace [/home/travis/build/jruby/jruby/test/mri/ruby/test_thread.rb:763]:
     [exec] <nil> expected but was
     [exec] <[]>.

Investigating.

@headius headius reopened this Dec 11, 2017

headius added a commit that referenced this issue Dec 11, 2017

@headius headius closed this Dec 11, 2017

eregon added a commit to ruby/spec that referenced this issue Jan 6, 2018

Thread#backtrace should never be nil for a living Thread (#581)
On MRI, immediately after a Thread gets created and before it starts
executing, its backtrace is an empty array.

This behavior changed from 2.0 onwards. On 1.9 it returned nil.

Testing for the backtrace of a recently-created Thread is an inherently
racy operation, so instead of specifically testing for an empty Array
let's at least test that we get **an** Array, which seems enough to
guarantee same-ish behavior.

See jruby/jruby#4891
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment