Skip to content

Conversation

@osyoyu
Copy link
Contributor

@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')
    }
@marshall-lee
Copy link

@hsbt Hi! Any chances this one is merged? Making HTTP requests in Ruby ractors become more & more desirable. And it seems like a safe change anyway. This sure will help a lot. Thanks

@tagomoris tagomoris merged commit b652fa5 into ruby:master May 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants