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

With jruby SecureRandom.random_number is always 0 #448

Closed
2 tasks done
duritong opened this issue Jan 17, 2023 · 6 comments
Closed
2 tasks done

With jruby SecureRandom.random_number is always 0 #448

duritong opened this issue Jan 17, 2023 · 6 comments

Comments

@duritong
Copy link

duritong commented Jan 17, 2023

Ensure the following before filing this issue

  • I verified it reproduces with the latest version with - uses: ruby/setup-ruby@v1 (see Versioning policy)

  • I tried to reproduce the issue locally by following the workflow steps (including all commands done by ruby/setup-ruby, except for Downloading Ruby & Extracting Ruby),
    and it did not reproduce locally (if it does reproduce locally, it's not a ruby/setup-ruby issue)

Are you running on a GitHub-hosted runner or a self-hosted runner?

GitHub-hosted runner

The workflow code or a link to the workflow file

https://github.com/duritong/ruby-actions-test/blob/main/.github/workflows/ruby.yml

Link to the log of a failed workflow job, or to a gist with the output

https://github.com/duritong/ruby-actions-test/actions/runs/3859056296/jobs/6578227554#step:4:106

The command and output of the failing step

The following script returns always 0 as a random number:

https://github.com/duritong/ruby-actions-test/blob/main/test.rb

So essentially I am showing that for many invocations SecureRandom.random_number on jRuby always returns 0.

If you run that script locally with jRuby this is not the case.

Any other notes?

This also affects tests in other projects: https://github.com/duritong/trocla/actions/runs/3859059179/jobs/6578233962

@duritong
Copy link
Author

CC @headius

@eregon
Copy link
Member

eregon commented Jan 17, 2023

This cannot be a bug of setup-ruby.
So it's most likely a bug of JRuby in combination with running in GitHub-hosted runners.
Therefore, could you open an issue at https://github.com/jruby/jruby/issues instead?

@eregon eregon closed this as completed Jan 17, 2023
@eregon
Copy link
Member

eregon commented Jan 18, 2023

FWIW I can actually reproduce the problem locally on linux-amd64 on JRuby 9.4.0.0 (jruby 9.4.0.0 (3.1.0) 2022-11-23 95c0ec159f OpenJDK 64-Bit Server VM 17.0.5+8 on 17.0.5+8 +jit [x86_64-linux]).

@eregon
Copy link
Member

eregon commented Jan 18, 2023

And it seems to happen on all 3 OS: https://github.com/eregon/actions-shell/actions/runs/3948629197/jobs/6758850494
Not sure why you couldn't repro locally, maybe you were not using the same JRuby version?

@headius
Copy link
Contributor

headius commented Jan 19, 2023

This should be filed with JRuby. It appears to be a bug in some very old code used to generate a random int or long by calling bytes on the self object, but it does not handle the bit math properly to produce the final value. This logic was not in use for SecureRandom until we moved to the securerandom gem, which depends on these callbacks to work properly.

@duritong
Copy link
Author

Thank you for looking into it. I filed: jruby/jruby#7586

Yeah, looks like my local jRuby wasn't recent enough - and therefor I leaned towards an issue with actions.

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

No branches or pull requests

3 participants