ActiveStorage::FileNotFoundError 但文件确实存在 [英] ActiveStorage::FileNotFoundError but the file actually exists

查看:50
本文介绍了ActiveStorage::FileNotFoundError 但文件确实存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

Every now and then my application errors out with ActiveStorage::FileNotFoundError. The actual file exists on disk. The model responds properly to .attached?.

重新启动 puma 解决了这个问题,该问题随后显然是随机再次弹出的……有些日子比其他日子更频繁.这在 Apache 和 mod_passenger 上以同样的方式发生.

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.

我做错了什么吗?

稍后编辑:下面是我对 puma、活动存储和错误的非常标准的配置

Later edit: below is my pretty standard configuration for puma, active storage and the error

ActiveStorage 配置

development:
  service: Disk
  root: <%= Rails.root.join("storage") %>

Puma 配置

# 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 相关?

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?

这篇关于ActiveStorage::FileNotFoundError 但文件确实存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆