将Paperclip与rails-redis一起使用时,“IOError - 关闭流”

时间:2015-01-20 21:57:15

标签: ruby-on-rails ruby redis paperclip redis-rails

我正在从网站下载一些图像,并使用Paperclip将这些图像上传到S3存储桶。加载图像后,我将实体存储到数据库中并返回它。 这包含在Rails.cache.fetch调用中以缓存响应。

它是这样的。

Rails.cache.fetch("/tvshows/#{id}/images") do
  result = self.find(id)
  if result.image.nil?
      result = self.load_image(result)
  end
  result
end

然而,图像将开始下载,最终我会得到IOError - closed stream:以下堆栈。

有谁能告诉我为什么会收到此错误以及如何避免错误?

IOError - closed stream:
  redis-store (1.1.4) lib/redis/store/marshalling.rb:29:in `_marshal'
  redis-store (1.1.4) lib/redis/store/marshalling.rb:5:in `set'
  redis-activesupport (4.0.0) lib/active_support/cache/redis_store.rb:163:in `write_entry'
  redis-activesupport (4.0.0) lib/active_support/cache/redis_store.rb:36:in `block in write'
  activesupport (4.2.0) lib/active_support/cache.rb:547:in `block in instrument'
  activesupport (4.2.0) lib/active_support/notifications.rb:166:in `instrument'
  activesupport (4.2.0) lib/active_support/cache.rb:547:in `instrument'
  redis-activesupport (4.0.0) lib/active_support/cache/redis_store.rb:34:in `write'
  activesupport (4.2.0) lib/active_support/cache.rb:588:in `save_block_result_to_cache'
  activesupport (4.2.0) lib/active_support/cache.rb:299:in `fetch'
  app/models/tv_show.rb:30:in `find_images'
  app/controllers/api/v1/tv_shows.rb:35:in `block (3 levels) in <class:TvShows>'
  grape (0.10.1) lib/grape/endpoint.rb:47:in `block in generate_api_method'
  grape (0.10.1) lib/grape/endpoint.rb:247:in `run'
  grape (0.10.1) lib/grape/endpoint.rb:195:in `block in call!'
  grape (0.10.1) lib/grape/middleware/base.rb:24:in `call!'
  grape (0.10.1) lib/grape/middleware/base.rb:18:in `call'
  grape (0.10.1) lib/grape/middleware/base.rb:24:in `call!'
  grape (0.10.1) lib/grape/middleware/base.rb:18:in `call'
  grape (0.10.1) lib/grape/middleware/base.rb:24:in `call!'
  grape (0.10.1) lib/grape/middleware/base.rb:18:in `call'
  grape (0.10.1) lib/grape/middleware/error.rb:27:in `block in call!'
  grape (0.10.1) lib/grape/middleware/error.rb:26:in `call!'
  grape (0.10.1) lib/grape/middleware/base.rb:18:in `call'
  rack (1.6.0) lib/rack/head.rb:13:in `call'
  rack (1.6.0) lib/rack/builder.rb:153:in `call'
  grape (0.10.1) lib/grape/endpoint.rb:196:in `call!'
  grape (0.10.1) lib/grape/endpoint.rb:184:in `call'
  rack-mount (0.8.3) lib/rack/mount/route_set.rb:152:in `block in call'
  rack-mount (0.8.3) lib/rack/mount/code_generation.rb:96:in `block in recognize'
  rack-mount (0.8.3) lib/rack/mount/code_generation.rb:75:in `optimized_each'
  rack-mount (0.8.3) lib/rack/mount/code_generation.rb:95:in `recognize'
  rack-mount (0.8.3) lib/rack/mount/route_set.rb:141:in `call'
  grape (0.10.1) lib/grape/api.rb:102:in `call'
  grape (0.10.1) lib/grape/api.rb:33:in `call!'
  grape (0.10.1) lib/grape/api.rb:29:in `call'
  actionpack (4.2.0) lib/action_dispatch/routing/mapper.rb:51:in `serve'
  actionpack (4.2.0) lib/action_dispatch/journey/router.rb:43:in `block in serve'
  actionpack (4.2.0) lib/action_dispatch/journey/router.rb:30:in `serve'
  actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:802:in `call'
  omniauth (1.2.2) lib/omniauth/strategy.rb:186:in `call!'
  omniauth (1.2.2) lib/omniauth/strategy.rb:164:in `call'
  omniauth (1.2.2) lib/omniauth/strategy.rb:186:in `call!'
  omniauth (1.2.2) lib/omniauth/strategy.rb:164:in `call'
  omniauth (1.2.2) lib/omniauth/strategy.rb:186:in `call!'
  omniauth (1.2.2) lib/omniauth/strategy.rb:164:in `call'
  omniauth (1.2.2) lib/omniauth/strategy.rb:186:in `call!'
  omniauth (1.2.2) lib/omniauth/strategy.rb:164:in `call'
  omniauth (1.2.2) lib/omniauth/builder.rb:59:in `call'
  warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
  warden (1.2.3) lib/warden/manager.rb:34:in `call'
  rack (1.6.0) lib/rack/etag.rb:24:in `call'
  rack (1.6.0) lib/rack/conditionalget.rb:25:in `call'
  rack (1.6.0) lib/rack/head.rb:13:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/flash.rb:260:in `call'
  rack (1.6.0) lib/rack/session/abstract/id.rb:225:in `context'
  rack (1.6.0) lib/rack/session/abstract/id.rb:220:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/cookies.rb:560:in `call'
  activerecord (4.2.0) lib/active_record/query_cache.rb:36:in `call'
  activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:647:in `call'
  activerecord (4.2.0) lib/active_record/migration.rb:378:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `_run_callbacks'
  activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_call_callbacks'
  activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/reloader.rb:73:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:84:in `protected_app_call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:79:in `better_errors_call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:57:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.2.0) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.2.0) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.2.0) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.2.0) lib/rails/rack/logger.rb:20:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.6.0) lib/rack/methodoverride.rb:22:in `call'
  rack (1.6.0) lib/rack/runtime.rb:18:in `call'
  rack (1.6.0) lib/rack/lock.rb:17:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/static.rb:113:in `call'
  rack (1.6.0) lib/rack/sendfile.rb:113:in `call'
  railties (4.2.0) lib/rails/engine.rb:518:in `call'
  railties (4.2.0) lib/rails/application.rb:164:in `call'
  rack (1.6.0) lib/rack/lock.rb:17:in `call'
  rack (1.6.0) lib/rack/content_length.rb:15:in `call'
  rack (1.6.0) lib/rack/handler/webrick.rb:89:in `service'
  /usr/local/var/rbenv/versions/2.2.0/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service'
  /usr/local/var/rbenv/versions/2.2.0/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'
  /usr/local/var/rbenv/versions/2.2.0/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'

1 个答案:

答案 0 :(得分:0)

这似乎是版本3.5.43.5.5上的回形针上的已知错误,如此处https://github.com/thoughtbot/paperclip/issues/875

如果您碰巧有其中一个版本显然解决方案是降级到3.5.2,但我想您可以升级到最新版本。