简体   繁体   English

使用 RAILS_ENV="production" bundle exec rails c 时无法分配内存 (NoMemoryError)

[英]failed to allocate memory (NoMemoryError) when using RAILS_ENV="production" bundle exec rails c

We just upgraded a Rails app to 4.2 to 5.2 , everything is working like a charm in development, but when we try to release the app on our production servers, we can't run any rails related commands (assets precompilation, migrate, console, etc.).我们刚刚将 Rails 应用程序升级到4.2 到 5.2 ,一切都像开发中的魅力一样工作,但是当我们尝试在生产服务器上发布应用程序时,我们无法运行任何与 rails 相关的命令(资产预编译、迁移、控制台、等等。)。

Here is the trace:这是跟踪:

Traceback (most recent call last):
    15: from bin/rails:4:in `<main>'
    14: from bin/rails:4:in `require'
    13: from /var/deploy/slaask_kb/web_head/shared/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/commands.rb:18:in `<top (required)>'
    12: from /var/deploy/slaask_kb/web_head/shared/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/command.rb:46:in `invoke'
    11: from /var/deploy/slaask_kb/web_head/shared/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/command/base.rb:65:in `perform'
    10: from /var/deploy/slaask_kb/web_head/shared/bundle/ruby/2.6.0/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
     9: from /var/deploy/slaask_kb/web_head/shared/bundle/ruby/2.6.0/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
     8: from /var/deploy/slaask_kb/web_head/shared/bundle/ruby/2.6.0/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
     7: from /var/deploy/slaask_kb/web_head/shared/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/commands/console/console_command.rb:95:in `perform'
     6: from /var/deploy/slaask_kb/web_head/shared/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/command/actions.rb:15:in `require_application_and_environment!'
     5: from /var/deploy/slaask_kb/web_head/shared/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/command/actions.rb:28:in `require_environment!'
     4: from /var/deploy/slaask_kb/web_head/shared/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/application.rb:337:in `require_environment!'
     3: from /var/deploy/slaask_kb/web_head/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:292:in `require'
     2: from /var/deploy/slaask_kb/web_head/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency'
     1: from /var/deploy/slaask_kb/web_head/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `block in require'
     /var/deploy/slaask_kb/web_head/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `require': failed to allocate memory (NoMemoryError)

We added puts file;我们添加了puts file; just before the result = super in dependencies.rb:291 , and a puts 'ERROR!'在 dependencies.rb:291 中result = super之前,并且一个puts 'ERROR!' in the rescue in dependencies.rb#L260 and here are the last loaded files:dependencies.rb#L260中的救援,这里是最后加载的文件:

active_support/per_thread_registry
rack/runtime
rack/utils
active_support/cache/strategy/local_cache_middleware
rack/body_proxy
rack/utils
tzinfo/data
ERROR!
active_support/core_ext/time/zones
ERROR!
Traceback (most recent call last):

More information:更多信息:

  • There is 52G of memory on the server, and we already tried adding 10G of SWAP.服务器上有52G的内存,我们已经尝试添加10G的SWAP。
  • Running htop is not giving any Memory leak运行htop不会造成任何内存泄漏

EDIT:编辑:

We tried removing the raise in dependencies.rb#L261 and of course the console loads, here are the logs:我们试图消除raise 在dependencies.rb#L261当然控制台的负载,这里的日志:

rack/body_proxy
rack/utils
tzinfo/data
ERROR!
active_support/core_ext/time/zones
tzinfo/data/definitions/America/New_York
ERROR!
/var/deploy/slaask_kb/web_head/shared/bundle/ruby/2.6.0/gems/tzinfo-1.2.5/lib/tzinfo/ruby_data_source.rb:35: warning: constant ::Data is deprecated
/var/deploy/slaask_kb/web_head/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:396: warning: constant ::Data is deprecated
/var/deploy/slaask_kb/web_head/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/inflector/methods.rb:283: warning: constant ::Data is deprecated
ERROR!
rails/console/app
active_support/all
action_controller
rails/console/helpers
active_record/base
pp
Loading production environment (Rails 5.2.3)
e2mmap
ERROR!
irb(main):001:0> 

I was able to reproduce the issue on a development environment (Windows Subsystem for Linux) too.我也能够在开发环境(Linux 的 Windows 子系统)上重现该问题。

We finally managed to solve it by upgrading tzinfo from 1.1 to 1.2.5 , as suggested here: https://github.com/tzinfo/tzinfo/issues/30我们最终设法通过将tzinfo1.1升级到1.2.5来解决它,如下所示: https : //github.com/tzinfo/tzinfo/issues/30

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 运行时遇到错误cmd RAILS_ENV =生产包exec rake资产:预编译 - got error when run cmd RAILS_ENV=production bundle exec rake assets:precompile NoMemoryError:无法分配内存-Ruby on Rails - NoMemoryError: failed to allocate memory - Ruby on Rails Capistrano:KILL RAILS_ENV =生产RAILS_GROUPS =资产捆绑执行rake资产:预编译 - Capistrano: Killed RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile RAILS_ENV = dev bundle exec rake db:seed不工作 - RAILS_ENV=dev bundle exec rake db:seed not working 使用&#39;RAILS_ENV =#{Rails.env} bundle exec用fork调用脚本。 。 &#39;不执行(Rails 2.1) - invoking a script with fork using 'RAILS_ENV=#{Rails.env} bundle exec . . ' doesn't execute (Rails 2.1) NoMemoryError:无法分配内存 - NoMemoryError: failed to allocate memory rails_env始终使用Nginx / Phusion Passenger进行“生产” - rails_env is 'production' always using Nginx/Phusion Passenger Bundle Exec Rake Test 和 rails db:migrate RAILS_ENV=test 不工作 - Bundle Exec Rake Test and rails db:migrate RAILS_ENV=test is not working 使用系统命令运行RAILS_ENV = production - Running RAILS_ENV=production with the system command 将Rails_Env设置为生产的预编译资产 - Precompiling assets with Rails_Env set as production
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM