ActiveStorage::FileNotFoundError 但文件确实存在

Nic*_*k M 6 ruby-on-rails puma rails-activestorage

我正在开发这个 Rails 6.0.21 应用程序(ruby 2.5.5),并使用 puma 3.12.2 作为开发 Web 服务器和具有本地磁盘服务的 ActiveStorage。

我的应用程序时不时会出现错误ActiveStorage::FileNotFoundError。实际文件存在于磁盘上。该模型正确响应.attached?。

重新启动 puma 解决了这个问题,然后该问题随后又明显随机地再次出现......有些日子比其他日子更频繁。Apache 上的 mod_passenger 也以同样的方式发生这种情况。

难道我做错了什么?

稍后编辑:下面是我对 puma、主动存储和错误的相当标准的配置

ActiveStorage配置

development:
  service: Disk
  root: <%= Rails.root.join("storage") %>
Run Code Online (Sandbox Code Playgroud)

美洲狮配置

# 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
Run Code Online (Sandbox Code Playgroud)

错误输出

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
Run Code Online (Sandbox Code Playgroud)

小智 1

您能分析应用程序对 fs 的 IO 访问吗?或者至少尝试在不同的机器上,以防它与操作系统或文件系统相关?