ruby-on-rails - ActiveStorage::FileNotFoundError 但文件实际存在

标签 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") %>

彪马配置
# 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

错误输出
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

最佳答案

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

关于ruby-on-rails - ActiveStorage::FileNotFoundError 但文件实际存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60323101/

相关文章:

ruby-on-rails - Ruby on Rails self.joins 或 self.where 不起作用?

ruby-on-rails - Rails 迁移顺序和 Git

sql - rails : Reducing the amount of ActiveStorage queries

ruby-on-rails - 为什么 puma 没有 Unicorn 那样的 `before_fork` 方法?

ruby-on-rails - ActiveStorage 如何在上传到 S3 之前转换图像?

ruby-on-rails - 在 Controller 测试中使用通过 Active Storage 上传的图像创建对象时遇到问题

ruby-on-rails - 在 Rails 3.2.8 中更改 PostgreSQL 数据库中整个列的数据类型

ruby-on-rails - Ruby on Rails 和 Heroku 问题

ruby-on-rails - Sidekiq错误: could not connect to server: No such file or directory

ruby - 我的网络服务器应该有什么样的进程和线程比例?