Skip to content
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

"undefined method DelegateClass for Rack::Session::Cookie:Class" #7647

Closed
dentarg opened this issue Feb 10, 2023 · 6 comments
Closed

"undefined method DelegateClass for Rack::Session::Cookie:Class" #7647

dentarg opened this issue Feb 10, 2023 · 6 comments

Comments

@dentarg
Copy link

dentarg commented Feb 10, 2023

Environment Information

  • JRuby version: jruby 9.4.2.0-SNAPSHOT (3.1.0) 2023-02-09 e4a5939c18 OpenJDK 64-Bit Server VM 11.0.18+10 on 11.0.18+10 +jit [x86_64-linux]
  • Operating system: Ubuntu 22.04.1 LTS (GitHub Actions)

Expected Behavior

Passing rack-protection tests :-)

Actual Behavior

This test in Sinatra / rack-protection pass on MRI and JRuby 9.3 but not with jruby-head: https://github.com/sinatra/sinatra/blob/b9064b9faa36d025530d50bc6e1eed802ff3692e/rack-protection/spec/lib/rack/protection/authenticity_token_spec.rb#L76-L85

CI log at https://github.com/sinatra/sinatra/actions/runs/4145731271/jobs/7170488680#step:7:40

I think it is this code in Rack 2 that triggers it? https://github.com/rack/rack/blob/v2.2.6.2/lib/rack/session/cookie.rb#L155-L162


Can probably (hopefully?) be boiled down to something much smaller for reproducing but thought I should report it earlier than later, maybe you have a hunch what it is.

@dentarg
Copy link
Author

dentarg commented Feb 10, 2023

Actually the test fails in released JRuby 9.4 too: https://github.com/sinatra/sinatra/actions/runs/4145890858/jobs/7170862315#step:7:40

jruby 9.4.1.0 (3.1.0) [20](https://github.com/sinatra/sinatra/actions/runs/4145890858/jobs/7170862315#step:4:24)23-02-07 237d5fa5f4 OpenJDK 64-Bit Server VM 11.0.18+10 on 11.0.18+10 +jit [x86_64-linux]

dentarg added a commit to sinatra/sinatra that referenced this issue Feb 10, 2023
dentarg added a commit to sinatra/sinatra that referenced this issue Feb 10, 2023
@dentarg
Copy link
Author

dentarg commented Feb 12, 2023

Can reproduce with: docker run --rm -it jruby:9.4.1.0 ruby -rbundler/inline -e "gemfile { source 'https://rubygems.org'; gem 'rack', '~> 2' }; Rack::Builder.new { use(Rack::Session::Cookie, key: 'rack.session') }"

arm64 $ docker run --rm -it jruby:9.4.1.0 ruby -rbundler/inline -e "gemfile { source 'https://rubygems.org'; gem 'rack', '~> 2' }; Rack::Builder.new { use(Rack::Session::Cookie, key: 'rack.session') }"
Feb 12, 2023 9:53:37 PM jnr.netdb.NativeProtocolsDB load
WARNING: Failed to load native protocols db
java.lang.RuntimeException: getprotobyname_r failed
	at jnr.netdb.NativeProtocolsDB$LinuxNativeProtocolsDB.getProtocolByName(NativeProtocolsDB.java:180)
...

NoMethodError: undefined method `DelegateClass' for Rack::Session::Cookie:Class
    <class:Cookie> at /usr/local/bundle/gems/rack-2.2.6.2/lib/rack/session/cookie.rb:155
  <module:Session> at /usr/local/bundle/gems/rack-2.2.6.2/lib/rack/session/cookie.rb:49
     <module:Rack> at /usr/local/bundle/gems/rack-2.2.6.2/lib/rack/session/cookie.rb:11
            <main> at /usr/local/bundle/gems/rack-2.2.6.2/lib/rack/session/cookie.rb:9
           require at org/jruby/RubyKernel.java:1057
            <main> at -e:1
     instance_eval at org/jruby/RubyBasicObject.java:2505
     instance_eval at org/jruby/RubyBasicObject.java:2533
        initialize at /usr/local/bundle/gems/rack-2.2.6.2/lib/rack/builder.rb:125
               new at org/jruby/RubyClass.java:897
            <main> at -e:1
... 12 levels...

arm64 $ echo $?
1

9.3.10 works

arm64 $ docker run --rm -it jruby:9.3.10 ruby -rbundler/inline -e "gemfile { source 'https://rubygems.org'; gem 'rack', '~> 2' }; Rack::Builder.new { use(Rack::Session::Cookie, key: 'rack.session') }"

arm64 $ echo $?
0

@dentarg
Copy link
Author

dentarg commented Feb 12, 2023

Oh, my repro works in CRuby 2.6 but fails on versions above that

intel $ ruby -v -rbundler/inline -e "gemfile { source 'https://rubygems.org'; gem 'rack', '~> 2' }; Rack::Builder.new { use(Rack::Session::Cookie, key: 'rack.session') }"
ruby 2.6.10p210 (2022-04-12 revision 67958) [x86_64-darwin21]

~/code/code-snippets/sinatra_jruby-issue-7647
intel $ echo $?
0
arm64 $ ruby -rbundler/inline -e "gemfile { source 'https://rubygems.org'; gem 'rack', '~> 2' }; Rack::Builder.new { use(Rack::Session::Cookie, key: 'rack.session') }"
/Users/dentarg/.arm64_rubies/3.1.3/lib/ruby/gems/3.1.0/gems/rack-2.2.6.2/lib/rack/session/cookie.rb:155:in `<class:Cookie>': undefined method `DelegateClass' for Rack::Session::Cookie:Class (NoMethodError)

      class SessionId < DelegateClass(Session::SessionId)
                        ^^^^^^^^^^^^^
	from /Users/dentarg/.arm64_rubies/3.1.3/lib/ruby/gems/3.1.0/gems/rack-2.2.6.2/lib/rack/session/cookie.rb:50:in `<module:Session>'
	from /Users/dentarg/.arm64_rubies/3.1.3/lib/ruby/gems/3.1.0/gems/rack-2.2.6.2/lib/rack/session/cookie.rb:11:in `<module:Rack>'
	from /Users/dentarg/.arm64_rubies/3.1.3/lib/ruby/gems/3.1.0/gems/rack-2.2.6.2/lib/rack/session/cookie.rb:9:in `<top (required)>'
	from -e:1:in `require'
	from -e:1:in `block in <main>'
	from /Users/dentarg/.arm64_rubies/3.1.3/lib/ruby/gems/3.1.0/gems/rack-2.2.6.2/lib/rack/builder.rb:125:in `instance_eval'
	from /Users/dentarg/.arm64_rubies/3.1.3/lib/ruby/gems/3.1.0/gems/rack-2.2.6.2/lib/rack/builder.rb:125:in `initialize'
	from -e:1:in `new'
	from -e:1:in `<main>'

Wonder why that isn't visible in the Sinatra tests 🤔

@dentarg
Copy link
Author

dentarg commented Feb 12, 2023

I guess JRuby is doing the right thing?

@dentarg
Copy link
Author

dentarg commented Feb 12, 2023

So it is (was) Rack missing an delegate require (only included in Rack 3). Still wondering why only JRuby fails without it :)

Oh well

@dentarg dentarg closed this as completed Feb 12, 2023
@dentarg
Copy link
Author

dentarg commented Feb 12, 2023

So it is (was) Rack missing an delegate require (only included in Rack 3)

Forgot to link: rack/rack#1610

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

No branches or pull requests

2 participants