Skip to content

Freeze some constants to improve Ractor compatibility #206

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

osyoyu
Copy link

@osyoyu osyoyu commented Feb 3, 2025

Freeze Net::HTTP::SSL_IVNAMES, Net::HTTPResponse::CODE_CLASS_TO_OBJ and Net::HTTPResponse::CODE_TO_OBJ to improve Ractor compatibility.

This change allows the following code to work:

Ractor.new {
  uri = URI.parse('http://example.com')
  http = Net::HTTP.new(uri.host, uri.port)
  http.open_timeout = nil
  http.read_timeout = nil
  http.get('/index.html')
}

Possibilities are that this patch breaks code which modify these constants. I have quickly skimmed over GitHub Code Search and have found only one instance where CODE_TO_OBJ is mutated, from 17-year-old code:
https://github.com/tolsen/rubydav/blob/62776abc293073da894b08c22d76952c918525c6/lib/rubydav/webdav.rb#L267

rubydav already needs a number of modifications to run under Ruby 3.4.1 even without this patch, so I think this change won't introduce additional major damage.

Freeze `Net::HTTP::SSL_IVNAMES`, `Net::HTTPResponse::CODE_CLASS_TO_OBJ`
and `Net::HTTPResponse::CODE_TO_OBJ` to improve Ractor compatibility.

This change allows the following code to work:

    Ractor.new {
      uri = URI.parse('http://example.com')
      http = Net::HTTP.new(uri.host, uri.port)
      http.open_timeout = nil
      http.read_timeout = nil
      http.get('/index.html')
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant