I've been having an issue where my local Rails / Puma server will lock up after running for a while. I suspect this may have to with the log data, but am honestly not even sure where to begin troubleshooting this.
What happens is that the server will lock up and is unresponsive, no log messages in console etc. The fix being to restart the local server. The odd thing is that when I run the command to stop the server (control + c) a bunch of normal log messages will be printed to the console before it shuts down. Additionally, I've noticed that if I periodically manually clear the console log (command + k) this doesn't happen. This leads me to believe that it may have something todo with a log file size limit.
I have not noticed this issue in any of the staging or production environments, only localhost.
Server is started with a Procfile using foreman with foreman start -f Procfile.dev
I'm wondering if this may be a STDOUT issue and not specifically related to Rails / Puma, but any advice in trying to track this down would be appreciated!
Current Local Setup (although this has been a consistent issue with pervious versions as well)
- macOS 13.6.1
- using
bash(notzsh) - Rails 7.0.8
- Ruby 2.7.8
- Puma 4.3.12
- Sidekiq 6.5.12
- foreman 0.87.2
config/environments/development.rb
require "active_support/core_ext/integer/time"
require "dotenv"
Dotenv.load
Rails.application.configure do
config.cache_classes = false
config.eager_load = false
config.consider_all_requests_local = true
config.server_timing = true
if Rails.root.join("tmp/caching-dev.txt").exist?
config.action_controller.perform_caching = true
config.action_controller.enable_fragment_cache_logging = true
config.cache_store = :memory_store
config.public_file_server.headers = {
"Cache-Control" => "public, max-age=#{2.days.to_i}"
}
else
config.action_controller.perform_caching = false
config.cache_store = :null_store
end
config.active_storage.service = :local
config.action_mailer.raise_delivery_errors = ActiveModel::Type::Boolean.new.cast(ENV.fetch('RAILS_MAILER_DELIVERY_ERRORS') { true })
config.action_mailer.perform_caching = false
config.active_support.deprecation = :log
config.active_support.disallowed_deprecation = :raise
config.active_support.disallowed_deprecation_warnings = []
config.active_record.migration_error = :page_load
config.active_record.verbose_query_logs = true
config.assets.quiet = true
config.assets.debug = true
config.assets.quiet = true
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
config.action_cable.mount_path = ":#{ ENV.fetch('DEFAULT_PORT') { 5000 } }/cable"
config.action_cable.url = "wss://#{ ENV.fetch('HOST') { 'localhost' } }:#{ ENV.fetch('DEFAULT_PORT') { 5000 } }/cable"
config.web_socket_server_url = "wss://#{ ENV.fetch('HOST') { 'localhost' } }:#{ ENV.fetch('DEFAULT_PORT') { 5000 } }/cable"
config.action_cable.allowed_request_origins = [/http:\/\/#{ENV['HOST']}*/, /https:\/\/#{ENV['HOST']}*/]
config.action_mailer.default_url_options = {
protocol: ENV.fetch('PROTOCOL') { 'https' },
host: ENV.fetch('HOST') { 'localhost' },
port: ENV.fetch('DEFAULT_PORT') { 3000 }
}
config.logger = ActiveSupport::Logger.new(STDOUT)
config.log_level = (ENV.fetch('RAILS_LOG_LEVEL') { 'debug' }).to_sym
config.sass.inline_source_maps = true
config.assets.unknown_asset_fallback = true
config.force_ssl = true
config.assets.prefix = '/dev-assets'
config.action_dispatch.cookies_same_site_protection = :strict
config.action_mailer.delivery_method = ENV.fetch('MAIL_DELIVERY_METHOD') { 'letter_opener' }.to_sym
config.action_mailer.perform_deliveries = true
end
config/puma/development.rb
require "dotenv"
Dotenv.load
max_threads_count = ENV.fetch('RAILS_MAX_THREADS') { 5 }
min_threads_count = ENV.fetch('RAILS_MIN_THREADS') { max_threads_count }
threads min_threads_count, max_threads_count
port ENV.fetch('DEFAULT_PORT') { 3000 }
environment ENV.fetch('RAILS_ENV') { 'development' }
workers ENV.fetch('WEB_CONCURRENCY') { 5 }
preload_app!
before_fork do
ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord)
end
on_worker_boot do
ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
end
if ENV.fetch('HOST') { 'localhost' } === 'localhost'
ssl_key = "#{File.join('config', 'certs', 'localhost', 'localhost.key')}"
ssl_crt = "#{File.join('config', 'certs', 'localhost', 'localhost.crt')}"
end
host = ENV.fetch('HOST') { 'localhost' }
port = ENV.fetch('SSL_PORT') { ENV.fetch('DEFAULT_PORT') { 3000 } }
ssl_bind host, port, {
key: ssl_key,
cert: ssl_crt,
verify_mode: 'none'
}
Procfile.dev
web: RAILS_ENV=development bundle exec puma
webpacker: ./bin/webpack-dev-server
redis: redis-server
worker1: bundle exec sidekiq -C config/sidekiq.yml
worker2: bundle exec sidekiq -C config/sidekiq.yml
worker3: bundle exec sidekiq -C config/sidekiq.yml
worker4: bundle exec sidekiq -C config/sidekiq.yml
worker5: bundle exec sidekiq -C config/sidekiq.yml
worker6: bundle exec sidekiq -C config/sidekiq.yml
worker7: bundle exec sidekiq -C config/sidekiq.yml
worker8: bundle exec sidekiq -C config/sidekiq.yml