Skip to content

7.0.1: Activesupport instrumentor: nil can't be coerced into Float (TypeError) #44167

@notapatch

Description

@notapatch

I have a Rails 7.0.1 test application that when it tries to load in multiple images (more than 2) it can regularly fail to load one or more images: on my dev system it happens most of the time.

Each time it fails you get the same 500 error: nil can't be coerced into Float (TypeError) from activesupport instrumenter. This happens on Rails 7.0 only and not on the almost identical 6.1 version.

Rails 7.0.1 - fails to load one of the images most of the time.

rails-7 0 1

Rails 6.1 - never seen if fail

rails-6 1 4

Stack trace

Code that throws the exception is here

Puma caught this error: nil can't be coerced into Float (TypeError)
/Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/activesupport-7.0.1/lib/active_support/notifications/instrumenter.rb:133:in `-'
/Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/activesupport-7.0.1/lib/active_support/notifications/instrumenter.rb:133:in `duration'
/Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/activesupport-7.0.1/lib/active_support/core_ext/enumerable.rb:61:in `map'
/Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/activesupport-7.0.1/lib/active_support/core_ext/enumerable.rb:61:in `sum'
/Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/activesupport-7.0.1/lib/active_support/core_ext/enumerable.rb:298:in `sum'
/Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/actionpack-7.0.1/lib/action_dispatch/middleware/server_timing.rb:26:in `block in call'
/Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/actionpack-7.0.1/lib/action_dispatch/middleware/server_timing.rb:25:in `each'
/Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/actionpack-7.0.1/lib/action_dispatch/middleware/server_timing.rb:25:in `map'
/Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/actionpack-7.0.1/lib/action_dispatch/middleware/server_timing.rb:25:in `call'
/Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/actionpack-7.0.1/lib/action_dispatch/middleware/executor.rb:14:in `call'
/Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/actionpack-7.0.1/lib/action_dispatch/middleware/static.rb:23:in `call'
/Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/rack-2.2.3/lib/rack/sendfile.rb:110:in `call'
/Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/actionpack-7.0.1/lib/action_dispatch/middleware/host_authorization.rb:137:in `call'
/Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/railties-7.0.1/lib/rails/engine.rb:530:in `call'
/Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/puma-5.5.2/lib/puma/configuration.rb:249:in `call'
/Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/puma-5.5.2/lib/puma/request.rb:77:in `block in handle_request'
/Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/puma-5.5.2/lib/puma/thread_pool.rb:340:in `with_force_shutdown'
/Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/puma-5.5.2/lib/puma/request.rb:76:in `handle_request'
/Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/puma-5.5.2/lib/puma/server.rb:447:in `process_client'
/Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/puma-5.5.2/lib/puma/thread_pool.rb:147:in `block in spawn_thread'

Steps to reproduce

I have a couple of apps one which works based on 6.1 and another that doesn't work based on 7.0.1

  1. Clone repo
  2. cd into rails directory
  3. bin/setup (standard setup except it runs db:seed)
  4. Repeat the following steps until you notice an image not loading
    1. bin/rails server
    2. browser opens localhost:3000 and keep "Network" tab open
    3. check if the 10 images all loaded
    4. close rails server and back to step i (It's important to stop server as normally once images loads they keep loading)
  5. Check network tab for the image that failed to load and look at the response

Browser Network tab showing exceptions

network-tab-showing-exception

There's very little code changes in the example applications. Basically:

  1. new application
  2. scaffold product
  3. install active_storage
  4. product has_one_attached image
  5. seed products with images
  6. Start running the server following the steps to reproduce ...

I've also tried:

  • With Rails 7.0 displaying static images from public - loads it fine.
  • All the browsers show the same issue
  • Rails 6.1 version works with or without spring but with spring every now and then it could hang until you did a spring stop.
  • Larger images 300 x 300 also failed in similar manner and not noticeably more often.

Expected behavior

It should load the images every time.

Actual behavior

Most of the time in the test application it fails

System configuration

Rails 7.0.1

Ruby 3.0.3

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions