Skip to content

Allow to use this gem in a Ractor - #73

Open
Edouard-chin wants to merge 1 commit into
gshutler:masterfrom
Shopify:ec-frozen-strings
Open

Allow to use this gem in a Ractor#73
Edouard-chin wants to merge 1 commit into
gshutler:masterfrom
Shopify:ec-frozen-strings

Conversation

@Edouard-chin

Copy link
Copy Markdown

Fix #70

Problem

I'd like to be able to use this gem inside a Ractor. This is currently not possible because all strings in this library aren't frozen.

Ractor.new do
  UserAgent::Browsers::Chrome::ChromeBrowsers
end.join

# <Thread:0x0000000127f1d128 run> terminated with exception (report_on_exception is true):
# 'block in <top (required)>': can not access non-shareable objects in constant UserAgent::Browsers::Chrome::ChromeBrowsers by non-main Ractor. (Ractor::IsolationError)

Solution

There is no codepaths that depend on mutating these strings so the solution is as simple as turning on the frozen_string_literal magic comment.

- Fix gshutler#70
- ### Problem

  I'd like to be able to use this gem inside a Ractor. This is
  currently not possible because all strings in this library
  aren't frozen.

  ```ruby
  Ractor.new do
    UserAgent::Browsers::Chrome::ChromeBrowsers
  end.join
  # <Thread:0x0000000127f1d128 run> terminated with exception (report_on_exception is true):
  # 'block in <top (required)>': can not access non-shareable objects in constant UserAgent::Browsers::Chrome::ChromeBrowsers by non-main Ractor. (Ractor::IsolationError)
  ```

  ### Solution

  There is no codepaths that depend on mutating these strings so the
  solution is as simple as turning on the `frozen_string_literal`
  magic comment.
@Edouard-chin

Edouard-chin commented Aug 3, 2026

Copy link
Copy Markdown
Author

@gshutler Sorry to bother and thanks a lot for your work on this gem. Do you by any chance still maintain this gem, and if yes would you mind having a look at this PR which should be straightforward I think.

For context, I discovered this problem in this gem because we are trying to change Rails to be able to serve requests from a Ractor (and Rails uses this gem as traversal dependencies for allowing/denying certain browsers).

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.

Enable # frozen_string_literal: true to optimize string handling

1 participant