问题
I am working on this Rails 6.0.21 application (ruby 2.5.5) and using puma 3.12.2 as development web server and ActiveStorage with local disk service.
Every now and then my application errors out with ActiveStorage::FileNotFoundError
. The actual file exists on disk. The model responds properly to .attached?.
Restarting puma solves the issue which then pops up again later apparently at random...some days more often than others. This is happening on Apache with mod_passenger in the same way.
Am I doing something wrong?
Later edit: below is my pretty standard configuration for puma, active storage and the error
ActiveStorage configuration
development:
service: Disk
root: <%= Rails.root.join("storage") %>
Puma configuration
# Puma can serve each request in a thread from an internal thread pool.
# The `threads` method setting takes two numbers: a minimum and maximum.
# Any libraries that use thread pools should be configured to match
# the maximum value specified for Puma. Default is set to 5 threads for minimum
# and maximum; this matches the default thread size of Active Record.
#
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
# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
#
port ENV.fetch("PORT") { 3000 }
# Specifies the `environment` that Puma will run in.
#
environment ENV.fetch("RAILS_ENV") { "development" }
# Specifies the `pidfile` that Puma will use.
pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
# Specifies the number of `workers` to boot in clustered mode.
# Workers are forked web server processes. If using threads and workers together
# the concurrency of the application would be max `threads` * `workers`.
# Workers do not work on JRuby or Windows (both of which do not support
# processes).
#
# workers ENV.fetch("WEB_CONCURRENCY") { 2 }
# Use the `preload_app!` method when specifying a `workers` number.
# This directive tells Puma to first boot the application and load code
# before forking the application. This takes advantage of Copy On Write
# process behavior so workers use less memory.
#
# preload_app!
# Allow puma to be restarted by `rails restart` command.
plugin :tmp_restart
Error output
ActionView::Template::Error (ActiveStorage::FileNotFoundError):
2: TODO cache this like forever
3: -->
4: <% if (current_website.icon.attached? rescue nil) %>
5: <link rel="apple-touch-icon" href="<%= current_website.icon.variant(resize: "57x57").service_url %>" />
6: <link rel="shortcut icon" href="<%= current_website.icon.variant(resize: "16x16").service_url %>" />
7: <link rel="icon" href="<%= current_website.icon.variant(resize: "16x16").service_url %>" />
8:
app/views/common/_page_head_icons.html.erb:5
app/views/common/_page_head.html.erb:61
app/views/layouts/admin.html.erb:3
回答1:
Can you profile the app for IO access to the fs? Or at least try on a different machine, in case it's OS or fs related?
来源:https://stackoverflow.com/questions/60323101/activestoragefilenotfounderror-but-the-file-actually-exists