-
Notifications
You must be signed in to change notification settings - Fork 140
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
Documentation around 4 -> 5 upgrade; ArgumentError: Start sender first #274
Comments
Is there anyone who could take a look at this? |
Hi @wjessop Sorry for the delay, I'm happy to help you figure this out. What you're seeing appears to be some kind of forking-related error, could you provide some more details on how your Puma server is configured? Particularly anything related to "Workers" as this appears to be how Puma creates new processes. Here's my repro attempt if its helpful to compare (this is just To give you a bit more insight, when the statsd client is forked (I'm guessing this is the case as the rails initializer probably runs once at startup, and then puma forks the process), we should be starting a new sender thread in the new process, but it appears that is not happening in your case, which is leading to this error. |
Here's our current datadog initialiser: # frozen_string_literal: true
require 'datadog/statsd'
# set up statsd monitoring
unless Rails.configuration.respond_to?(:statsd)
statsd = Datadog::Statsd.new(
tags: {
env: Rails.env
},
disable_telemetry: Rails.env != 'production'
)
Rails.configuration.statsd = statsd
end The Puma config: # frozen_string_literal: true
require 'puma_worker_killer'
require 'barnes'
workers Integer(ENV.fetch('WEB_CONCURRENCY', 1))
threads_count = Integer(ENV.fetch('PUMA_MAX_THREADS', 1))
threads(threads_count, threads_count)
preload_app!
rackup DefaultRackup
environment ENV.fetch('RACK_ENV', 'development')
worker_timeout 15
worker_shutdown_timeout 8
on_worker_boot do
# Worker specific setup for Rails 4.1+
# See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot
Makara::Context.release_all
ActiveRecord::Base.establish_connection
SemanticLogger.reopen
end
# Puma worker killer. Bandaid for memory issues.
before_fork do
PumaWorkerKiller.enable_rolling_restart(3600) # Overriding 6 hour default to do it every hour to kill off memory-hungry workers that hang around.
Barnes.start # see https://devcenter.heroku.com/articles/language-runtime-metrics-ruby
end Env for the staging environment where we were trying this out: WEB_CONCURRENCY: 2
PUMA_MAX_THREADS: 5 I figure the same as you, I'm probably missing some config but don't know what that would be. |
Thanks for the extra details, I'm unfortunately still not able to reproduce this. I have a few questions that can hopefully help us get to the bottom of this:
Without a reproduction I'm stuck reading through the code and I'm unfortunately not having much luck figuring out how you'd get into this state. As a workaround, you could try setting |
ping @wjessop in case you missed the above |
Sorry @scottopell, was on vacation! Will try to take a look at this this week. |
@wjessop one more ping if you still need help |
Sorry Scott, lots going on!
Yes, it's only dogstatsd-ruby changing.
Ruby 2.7.5
I don't think anything remains up, but I've only seen one instance of the error in the logs.
There's no stack trace, just the log, I don't have the log output to hand, but I recall it wasn't particularly useful.
We could try this but I think we'd still want to solve the issue with the error. I think what would help would be if you could provide a canonical example of what a datadog config looks like when using Puma in pre-forking mode (probably the most common Rails app server and configuration). Saying "Using a singleton instance of the DogStatsD client instead of creating a new instance whenever you need one; this will let the buffering mechanism flush metrics regularly" in the docs is somewhat abstract, a concrete example would be really helpful to compare to what we're currently doing. |
Hey Scott, if you've got it a canonical example of what a datadog config looks like when using Puma in pre-forking mode would be really helpful here. |
@scottopell Any chance you could give an example? |
I'm unsure what I need to do to make the 4 to 5 upgrade work. I see the README file has some detail:
but I thought we were using a singleton instance, and I don't think we want to be sprinkling
#close
around the code. The current way we're creating the instance is in an initialiser:then we use it like so:
Deployed on Heroku using Puma, we're getting an error
#<ArgumentError: Start sender first>
that is crashing the Rails (6.1.7.3) process on boot. Is there something else we should be doing?The text was updated successfully, but these errors were encountered: