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

NoMethodError: undefined method `stats' for nil:NilClass #49

Open
paneq opened this issue Aug 25, 2023 · 1 comment · May be fixed by #68
Open

NoMethodError: undefined method `stats' for nil:NilClass #49

paneq opened this issue Aug 25, 2023 · 1 comment · May be fixed by #68

Comments

@paneq
Copy link

paneq commented Aug 25, 2023

Hey, thanks for this very useful plugin.

We are experiencing a bug during deployments. It appears that metrics endpoint is served earlier than the rest of the application. This leads to:

NoMethodError: undefined method `stats' for nil:NilClass` exception.

Software versions: puma (6.3.1), puma-metrics (1.3.0)

Stacktrace:

NoMethodError: undefined method `stats' for nil:NilClass (NoMethodError)

      }.merge(@server.stats).merge(super)
                     ^^^^^^
  from puma/single.rb:20:in `stats'
  from puma/launcher.rb:115:in `stats'
  from puma/metrics/app.rb:26:in `retrieve_and_parse_stats!'
  from puma/metrics/app.rb:17:in `call'
  from puma/request.rb:100:in `block in handle_request'
  from puma/thread_pool.rb:344:in `with_force_shutdown'
  from puma/request.rb:99:in `handle_request'
  from puma/server.rb:443:in `process_client'
  from puma/server.rb:245:in `block in run'
  from puma/thread_pool.rb:151:in `block in spawn_thread'

I am not exactly sure how this can be fixed, should Puma check if @server is nil before invoking merge:

  class Single < Runner
    # @!attribute [r] stats
    def stats
      {
        started_at: utc_iso8601(@started_at)
      }.merge(@server.stats).merge(super)
    end

or should the metrics plugin check some status on @launcher before invoking stats.

      def retrieve_and_parse_stats!
        puma_stats = @launcher.stats

Related code:

@harmjanblok
Copy link
Owner

As the method retrieve_and_parse_stats! is called every scrape (like every 30 seconds, depending on your prometheus configuration), I think adding a rescue or additional condition to the if/else clause should be sufficient?
Assuming the described NoMethodError applies to boottime only?

@dgsuarez dgsuarez linked a pull request Oct 4, 2024 that will close this issue
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 a pull request may close this issue.

2 participants