Skip to content

Make parser's #inspect work in non-main Ractors - #262

Open
y-yagi wants to merge 1 commit into
ruby:masterfrom
y-yagi:fix_parser_inspect_in_ractor
Open

Make parser's #inspect work in non-main Ractors#262
y-yagi wants to merge 1 commit into
ruby:masterfrom
y-yagi:fix_parser_inspect_in_ractor

Conversation

@y-yagi

@y-yagi y-yagi commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

URI::RFC3986_PARSER.inspect and URI::RFC2396_PARSER.inspect raised Ractor::IsolationError when called from a non-main Ractor:

Ractor.new { URI::RFC3986_PARSER.inspect }.value
#=> can not access class variables from non-main Ractors
#   (@@to_s from URI::RFC3986_Parser)

Ractor.new { URI::RFC2396_PARSER.inspect }.value
#=> can not access non-shareable objects in constant
#   URI::RFC2396_Parser::TO_S by non-main ractor

Both parsers kept Kernel.instance_method(:to_s) at the class level, in a class variable and in a constant respectively. An UnboundMethod is not shareable, so neither can be read from a non-main Ractor.

UnboundMethod is Ractor-shareable only Ruby 4.0. And, parser's inspect only for debug and performance isn't so important, I think

So this commit changes not to held the method and just call it in the method.

`URI::RFC3986_PARSER.inspect` and `URI::RFC2396_PARSER.inspect` raised
`Ractor::IsolationError` when called from a non-main Ractor:

    Ractor.new { URI::RFC3986_PARSER.inspect }.value
    #=> can not access class variables from non-main Ractors
    #   (@@to_s from URI::RFC3986_Parser)

    Ractor.new { URI::RFC2396_PARSER.inspect }.value
    #=> can not access non-shareable objects in constant
    #   URI::RFC2396_Parser::TO_S by non-main ractor

Both parsers kept `Kernel.instance_method(:to_s)` at the class level, in a
class variable and in a constant respectively. An `UnboundMethod` is not
shareable, so neither can be read from a non-main Ractor.

`UnboundMethod` is Ractor-shareable only Ruby 4.0. And, parser's inspect only for
debug and performance isn't so important, I think

So this commit changes not to held the method and just call it in the
method.
@y-yagi
y-yagi marked this pull request as ready for review September 9, 2026 09:55
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.

1 participant