简体   繁体   中英

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.).

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; just before the result = super in dependencies.rb:291 , and a puts 'ERROR!' in the rescue in dependencies.rb#L260 and here are the last loaded files:

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.
  • Running htop is not giving any Memory leak

EDIT:

We tried removing the raise in dependencies.rb#L261 and of course the console loads, here are the logs:

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM