Skip to content

ZJIT: undefined method for nil on Rails 8.1.2 app #943

@hachi8833

Description

@hachi8833

I encountered subtle errors on a new Rails 8.1.2 app with ZJIT, such as:

error on Puma (click to expand) ``` Puma caught this error: undefined method 'group_by' for nil (NoMethodError) /Users/hachi8833/.anyenv/envs/rbenv/versions/4.0.1/lib/ruby/gems/4.0.0/gems/actionpack-8.1.2/lib/action_dispatch/middleware/server_timing.rb:66:in 'ActionDispatch::ServerTiming#call' /Users/hachi8833/.anyenv/envs/rbenv/versions/4.0.1/lib/ruby/gems/4.0.0/gems/rails_live_reload-0.5.0/lib/rails_live_reload/middleware/base.rb:19:in 'RailsLiveReload::Middleware::Base#call!' /Users/hachi8833/.anyenv/envs/rbenv/versions/4.0.1/lib/ruby/gems/4.0.0/gems/rails_live_reload-0.5.0/lib/rails_live_reload/middleware/base.rb:9:in 'RailsLiveReload::Middleware::Base#call' /Users/hachi8833/.anyenv/envs/rbenv/versions/4.0.1/lib/ruby/gems/4.0.0/gems/actionpack-8.1.2/lib/action_dispatch/middleware/executor.rb:20:in 'ActionDispatch::Executor#call' /Users/hachi8833/.anyenv/envs/rbenv/versions/4.0.1/lib/ruby/gems/4.0.0/gems/propshaft-1.3.1/lib/propshaft/server.rb:37:in 'Propshaft::Server#call' /Users/hachi8833/.anyenv/envs/rbenv/versions/4.0.1/lib/ruby/gems/4.0.0/gems/actionpack-8.1.2/lib/action_dispatch/middleware/static.rb:27:in 'ActionDispatch::Static#call' /Users/hachi8833/.anyenv/envs/rbenv/versions/4.0.1/lib/ruby/gems/4.0.0/gems/rack-3.2.4/lib/rack/sendfile.rb:131:in 'Rack::Sendfile#call' /Users/hachi8833/.anyenv/envs/rbenv/versions/4.0.1/lib/ruby/gems/4.0.0/gems/actionpack-8.1.2/lib/action_dispatch/middleware/host_authorization.rb:143:in 'ActionDispatch::HostAuthorization#call' /Users/hachi8833/.anyenv/envs/rbenv/versions/4.0.1/lib/ruby/gems/4.0.0/gems/rack-mini-profiler-4.0.1/lib/mini_profiler.rb:334:in 'Rack::MiniProfiler#call' /Users/hachi8833/.anyenv/envs/rbenv/versions/4.0.1/lib/ruby/gems/4.0.0/gems/railties-8.1.2/lib/rails/engine.rb:534:in 'Rails::Engine#call' /Users/hachi8833/.anyenv/envs/rbenv/versions/4.0.1/lib/ruby/gems/4.0.0/gems/puma-7.2.0/lib/puma/configuration.rb:296:in 'Puma::Configuration::ConfigMiddleware#call' /Users/hachi8833/.anyenv/envs/rbenv/versions/4.0.1/lib/ruby/gems/4.0.0/gems/puma-7.2.0/lib/puma/request.rb:103:in 'block in Puma::Request#handle_request' /Users/hachi8833/.anyenv/envs/rbenv/versions/4.0.1/lib/ruby/gems/4.0.0/gems/puma-7.2.0/lib/puma/thread_pool.rb:355:in 'Puma::ThreadPool#with_force_shutdown' /Users/hachi8833/.anyenv/envs/rbenv/versions/4.0.1/lib/ruby/gems/4.0.0/gems/puma-7.2.0/lib/puma/request.rb:102:in 'Puma::Request#handle_request' /Users/hachi8833/.anyenv/envs/rbenv/versions/4.0.1/lib/ruby/gems/4.0.0/gems/puma-7.2.0/lib/puma/server.rb:503:in 'Puma::Server#process_client' /Users/hachi8833/.anyenv/envs/rbenv/versions/4.0.1/lib/ruby/gems/4.0.0/gems/puma-7.2.0/lib/puma/server.rb:262:in 'block in Puma::Server#run' /Users/hachi8833/.anyenv/envs/rbenv/versions/4.0.1/lib/ruby/gems/4.0.0/gems/puma-7.2.0/lib/puma/thread_pool.rb:182:in 'block in Puma::ThreadPool#spawn_thread' ```

or

Image

Please find the following repo fore reproduction:

As noted on README, Ruby 4.0.1 YJIT does not cause the errors.

It seems the behaviors of Puma (uma::Request#fast_write_str), Lookbook and ActionView (ActionView::OutputBuffer), and ServerTiming middleware are affected by ZJIT: some values are unexpectedly turns into nil...

The repo contains to_suppress_errors branch to apply some patches to suppress errors (Gemini 4 Pro created).

Hope this helps you to fix the subtle bugs 🙏

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions