Rails:创建/更新记录时出现 EOF 错误

Posted

技术标签:

【中文标题】Rails:创建/更新记录时出现 EOF 错误【英文标题】:Rails: EOF Error when creating/updating a record 【发布时间】:2019-06-28 10:01:16 【问题描述】:

我最近偶然发现我的 rails 应用程序存在问题。 我正在使用 ruby​​ 2.1.0 和 Rails 3.2.7(我知道),最近,当我创建/更新任何模型的任何记录时,我的应用程序中出现 EOFError - bad content body: 错误。一切似乎都在数据库级别工作,因为如果我重新加载,可以看到更改(如果我创建新记录,它会显示在列表视图中,如果我更新记录,则会反映更改)。

这里是rails服务器的踪迹:

EOFError - bad content body:
  (gem) rack-1.4.7/lib/rack/multipart/parser.rb:83:in `block in fast_forward_to_first_boundary'
  (gem) rack-1.4.7/lib/rack/multipart/parser.rb:81:in `fast_forward_to_first_boundary'
  (gem) rack-1.4.7/lib/rack/multipart/parser.rb:17:in `parse'
  (gem) rack-1.4.7/lib/rack/multipart.rb:25:in `parse_multipart'
  (gem) rack-1.4.7/lib/rack/request.rb:336:in `parse_multipart'
  (gem) rack-1.4.7/lib/rack/request.rb:201:in `POST'
  (gem) actionpack-3.2.7/lib/action_dispatch/http/request.rb:231:in `POST'
  (gem) actionpack-3.2.7/lib/action_dispatch/http/parameters.rb:10:in `parameters'
  (gem) actionpack-3.2.7/lib/action_dispatch/http/filter_parameters.rb:33:in `filtered_parameters'
  (gem) actionpack-3.2.7/lib/action_controller/metal/instrumentation.rb:21:in `process_action'
  (gem) actionpack-3.2.7/lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
  (gem) activerecord-3.2.7/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
  (gem) actionpack-3.2.7/lib/abstract_controller/base.rb:121:in `process'
  (gem) actionpack-3.2.7/lib/abstract_controller/rendering.rb:45:in `process'
  (gem) actionpack-3.2.7/lib/action_controller/metal.rb:203:in `dispatch'
  (gem) actionpack-3.2.7/lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
  (gem) actionpack-3.2.7/lib/action_controller/metal.rb:246:in `block in action'
  (gem) actionpack-3.2.7/lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
  (gem) actionpack-3.2.7/lib/action_dispatch/routing/route_set.rb:36:in `call'
  (gem) journey-1.0.4/lib/journey/router.rb:68:in `block in call'
  (gem) journey-1.0.4/lib/journey/router.rb:56:in `call'
  (gem) actionpack-3.2.7/lib/action_dispatch/routing/route_set.rb:600:in `call'
  (gem) omniauth-1.4.2/lib/omniauth/strategy.rb:186:in `call!'
  (gem) omniauth-1.4.2/lib/omniauth/strategy.rb:164:in `call'
  (gem) warden-1.2.1/lib/warden/manager.rb:35:in `block in call'
  (gem) warden-1.2.1/lib/warden/manager.rb:34:in `call'
  (gem) actionpack-3.2.7/lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
  (gem) rack-1.4.7/lib/rack/etag.rb:23:in `call'
  (gem) rack-1.4.7/lib/rack/conditionalget.rb:25:in `call'
  (gem) actionpack-3.2.7/lib/action_dispatch/middleware/head.rb:14:in `call'
  (gem) actionpack-3.2.7/lib/action_dispatch/middleware/params_parser.rb:21:in `call'
  (gem) actionpack-3.2.7/lib/action_dispatch/middleware/flash.rb:242:in `call'
  (gem) rack-1.4.7/lib/rack/session/abstract/id.rb:210:in `context'
  (gem) rack-1.4.7/lib/rack/session/abstract/id.rb:205:in `call'
  (gem) actionpack-3.2.7/lib/action_dispatch/middleware/cookies.rb:338:in `call'
  (gem) activerecord-3.2.7/lib/active_record/query_cache.rb:64:in `call'
  (gem) activerecord-3.2.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:473:in `call'
  (gem) actionpack-3.2.7/lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
  (gem) activesupport-3.2.7/lib/active_support/callbacks.rb:405:in `_run__451408873423695737__call__1903216192202827668__callbacks'
  (gem) activesupport-3.2.7/lib/active_support/callbacks.rb:405:in `__run_callback'
  (gem) activesupport-3.2.7/lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
  (gem) activesupport-3.2.7/lib/active_support/callbacks.rb:81:in `run_callbacks'
  (gem) actionpack-3.2.7/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  (gem) actionpack-3.2.7/lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
  (gem) better_errors-0.7.2/lib/better_errors/middleware.rb:84:in `protected_app_call'
  (gem) better_errors-0.7.2/lib/better_errors/middleware.rb:79:in `better_errors_call'
  (gem) better_errors-0.7.2/lib/better_errors/middleware.rb:56:in `call'
  (gem) actionpack-3.2.7/lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
  (gem) actionpack-3.2.7/lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  (gem) railties-3.2.7/lib/rails/rack/logger.rb:26:in `call_app'
  (gem) railties-3.2.7/lib/rails/rack/logger.rb:16:in `call'
  (gem) actionpack-3.2.7/lib/action_dispatch/middleware/request_id.rb:22:in `call'
  (gem) rack-1.4.7/lib/rack/methodoverride.rb:21:in `call'
  (gem) rack-1.4.7/lib/rack/runtime.rb:17:in `call'
  (gem) activesupport-3.2.7/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  (gem) rack-1.4.7/lib/rack/lock.rb:15:in `call'
  (gem) actionpack-3.2.7/lib/action_dispatch/middleware/static.rb:62:in `call'
  /home/oscar/.asdf/installs/ruby/2.1.0/lib/ruby/gems/2.1.0/bundler/gems/raven-ruby-16a463b59142/lib/raven/integrations/rack.rb:54:in `call'
  (gem) railties-3.2.7/lib/rails/engine.rb:479:in `call'
  (gem) railties-3.2.7/lib/rails/application.rb:220:in `call'
  (gem) rack-1.4.7/lib/rack/content_length.rb:14:in `call'
  (gem) railties-3.2.7/lib/rails/rack/log_tailer.rb:17:in `call'
  (gem) thin-1.4.1/lib/thin/connection.rb:80:in `block in pre_process'
  (gem) thin-1.4.1/lib/thin/connection.rb:78:in `pre_process'
  (gem) thin-1.4.1/lib/thin/connection.rb:53:in `process'
  (gem) thin-1.4.1/lib/thin/connection.rb:38:in `receive_data'
  (gem) eventmachine-1.0.9.1/lib/eventmachine.rb:193:in `run'
  (gem) thin-1.4.1/lib/thin/backends/base.rb:63:in `start'
  (gem) thin-1.4.1/lib/thin/server.rb:159:in `start'
  (gem) rack-1.4.7/lib/rack/handler/thin.rb:13:in `run'
  (gem) rack-1.4.7/lib/rack/server.rb:268:in `start'
  (gem) railties-3.2.7/lib/rails/commands/server.rb:70:in `start'
  (gem) railties-3.2.7/lib/rails/commands.rb:55:in `block in <top (required)>'
  (gem) railties-3.2.7/lib/rails/commands.rb:50:in `<top (required)>'
  script/rails:6:in `<main>'

有人遇到过这样的问题吗?

【问题讨论】:

它说:多部分的身体坏了。你使用稳定的 HTTP 客户端吗? 是的,我没有改变任何东西。我唯一做的就是更新 gem 版本。也许它正在造成麻烦?另外,我发现这个问题不会影响当前使用该应用程序的用户。那部分真的很困扰我。 我刚刚在 Firefox 中尝试过,一切正常。是浏览器相关的吗? 可能是插件损坏 我在更新我的 gems 之前恢复到提交,强制安装 gems。仍然收到错误。 【参考方案1】:

问题可以找到here:

在问题中有许多解决问题的建议。它对我有用的是这个:

module Rack
  module Multipart
    class << self
      alias_method :original_parse_multipart, :parse_multipart
      def parse_multipart(env)
        begin
          original_parse_multipart(env)
        rescue EOFError => e 
          nil
        end
      end
    end
  end
end

我不是很喜欢,因为它只是忽略了问题,并没有指出错误的根源。

【讨论】:

以上是关于Rails:创建/更新记录时出现 EOF 错误的主要内容,如果未能解决你的问题,请参考以下文章

通过Rails中的关联使用has_many创建新模型时出现不允许的参数错误

使用 Kaitai Struct 时出现 EOF 错误

推送到 Elastic Beanstalk 时出现 Rails 捆绑错误

尝试在存储过程中更新时出现 MySQL 错误代码 1175

创建记录时出现重复键错误

尝试在 Rails 中发布文件时出现 405 错误