Skip to content

Conversation

@MSP-Greg
Copy link
Member

Description

PR #2633 throws deprecation warnings in Ruby 3. Fix by using Random.bytes when available.

Your checklist for this pull request

  • I have reviewed the guidelines for contributing to this repository.
  • I have added (or updated) appropriate tests if this PR fixes a bug or adds a feature.
  • My pull request is 100 lines added/removed or less so that it can be easily reviewed.
  • If this PR doesn't need tests (docs change), I added [ci skip] to the title of the PR.
  • If this closes any issues, I have added "Closes #issue" to the PR description or my commit messages.
  • I have updated the documentation accordingly.
  • All new and existing tests passed, including Rubocop.

Copy link
Contributor

@eregon eregon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@MSP-Greg
Copy link
Member Author

I looked at this one more time, and thought maybe the below was a little clearer. Note that this code is only called on Puma start/restart, once for each ssl binder/listener.

// Random.bytes available in Ruby 2.5 and later, Random::DEFAULT deprecated in 3.0
#ifdef HAVE_RANDOM_BYTES
  bytes_func = rb_cRandom;
#else
  bytes_func = rb_const_get(rb_cRandom, rb_intern_const("DEFAULT"));
#endif
  session_id_bytes = rb_funcall(bytes_func, rb_intern_const("bytes"),
                                1, ULL2NUM(SSL_MAX_SSL_SESSION_ID_LENGTH));

If anyone has objections, please let me know, otherwise I'll change. I also added the comment to extconf.rb, and output a line like checking for Random.bytes... <yes/no>...

@onlined
Copy link
Contributor

onlined commented Jun 16, 2021

I like the approach, but I don't like the name bytes_func. The name suggests that the object is a method or function, but it's not. A name like object_with_bytes_method could be better, or you can do this without a variable:

  // Random.bytes available in Ruby 2.5 and later, Random::DEFAULT deprecated in 3.0
  session_id_bytes = rb_funcall(
#ifdef HAVE_RANDOM_BYTES
    rb_cRandom,
#else
    rb_const_get(rb_cRandom, rb_intern_const("DEFAULT")),
#endif
    bytes_func, 
    rb_intern_const("bytes"),
    1, ULL2NUM(SSL_MAX_SSL_SESSION_ID_LENGTH)
  );

@MSP-Greg MSP-Greg merged commit 6a085e6 into puma:master Jun 16, 2021
@MSP-Greg MSP-Greg deleted the 00-random branch October 31, 2021 15:23
MSP-Greg added a commit to MSP-Greg/puma that referenced this pull request Feb 13, 2022
MSP-Greg added a commit to MSP-Greg/puma that referenced this pull request Feb 13, 2022
nateberkopec pushed a commit that referenced this pull request Feb 16, 2022
* Actions - add Ruby 3.0 and 3.1

* .gitignore - add entry for local use

* test_puma_server_ssl.rb - backport fix

888b0213f11

* minissl.c and extconf.rb - backport fixes

Fixes from PR's:
#2535
#2633
#2642
JuanitoFatas pushed a commit to JuanitoFatas/puma that referenced this pull request Sep 9, 2022
Co-authored-by: Ekin Dursun <[email protected]>

Co-authored-by: Ekin Dursun <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants