can't modify frozen Module (FrozenError)

81 views Asked by At

locally the app seems to be working fine, I can start the server and the app loads correctly, however, when I deploy to a remote environment I get 500 error, then looking at the logs I see this error can't modify frozen Module (FrozenError)

Here's the full Traceback:

Traceback (most recent call last):
    56: from bin/rails:11:in `<main>'
    55: from bin/rails:11:in `require'
    54: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-5.2.8.1/lib/rails/commands.rb:18:in `<top (required)>'
    53: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-5.2.8.1/lib/rails/command.rb:46:in `invoke'
    52: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-5.2.8.1/lib/rails/command/base.rb:69:in `perform'
    51: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/thor-1.3.0/lib/thor.rb:527:in `dispatch'
    50: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/thor-1.3.0/lib/thor/invocation.rb:127:in `invoke_command'
    49: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/thor-1.3.0/lib/thor/command.rb:28:in `run'
    48: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-5.2.8.1/lib/rails/commands/runner/runner_command.rb:29:in `perform'
    47: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-5.2.8.1/lib/rails/command/actions.rb:15:in `require_application_and_environment!'
    46: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-5.2.8.1/lib/rails/command/actions.rb:28:in `require_environment!'
    45: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-5.2.8.1/lib/rails/application.rb:337:in `require_environment!'
    44: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `require'
    43: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:257:in `load_dependency'
    42: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `block in require'
    41: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/zeitwerk-2.6.12/lib/zeitwerk/kernel.rb:38:in `require'
    40: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/zeitwerk-2.6.12/lib/zeitwerk/kernel.rb:38:in `require'
    39: from /opt/thedeployer/pangea.rewardops.net/releases/20240129183011Z/config/environment.rb:9:in `<top (required)>'
    38: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-5.2.8.1/lib/rails/railtie.rb:190:in `method_missing'
    37: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-5.2.8.1/lib/rails/railtie.rb:190:in `public_send'
    36: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-5.2.8.1/lib/rails/application.rb:361:in `initialize!'
    35: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-5.2.8.1/lib/rails/initializable.rb:60:in `run_initializers'
    34: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/2.6.0/tsort.rb:205:in `tsort_each'
    33: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/2.6.0/tsort.rb:226:in `tsort_each'
    32: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/2.6.0/tsort.rb:347:in `each_strongly_connected_component'
    31: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/2.6.0/tsort.rb:347:in `call'
    30: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/2.6.0/tsort.rb:347:in `each'
    29: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/2.6.0/tsort.rb:349:in `block in each_strongly_connected_component'
    28: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/2.6.0/tsort.rb:431:in `each_strongly_connected_component_from'
    27: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/2.6.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
    26: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/2.6.0/tsort.rb:228:in `block in tsort_each'
    25: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-5.2.8.1/lib/rails/initializable.rb:61:in `block in run_initializers'
    24: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-5.2.8.1/lib/rails/initializable.rb:32:in `run'
    23: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-5.2.8.1/lib/rails/initializable.rb:32:in `instance_exec'
    22: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-5.2.8.1/lib/rails/application/finisher.rb:69:in `block in <module:Finisher>'
    21: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-5.2.8.1/lib/rails/application/finisher.rb:69:in `each'
    20: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-5.2.8.1/lib/rails/engine.rb:356:in `eager_load!'
    19: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-5.2.8.1/lib/rails/engine.rb:475:in `eager_load!'
    18: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-5.2.8.1/lib/rails/engine.rb:475:in `each'
    17: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-5.2.8.1/lib/rails/engine.rb:477:in `block in eager_load!'
    16: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-5.2.8.1/lib/rails/engine.rb:477:in `each'
    15: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-5.2.8.1/lib/rails/engine.rb:478:in `block (2 levels) in eager_load!'
    14: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:246:in `require_dependency'
    13: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:334:in `depend_on'
    12: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:356:in `require_or_load'
    11: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:37:in `load_interlock'
    10: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies/interlock.rb:13:in `loading'
     9: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/activesupport-5.2.8.1/lib/active_support/concurrency/share_lock.rb:151:in `exclusive'
     8: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies/interlock.rb:14:in `block in loading'
     7: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:37:in `block in load_interlock'
     6: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:378:in `block in require_or_load'
     5: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `require'
     4: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:257:in `load_dependency'
     3: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `block in require'
     2: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/zeitwerk-2.6.12/lib/zeitwerk/kernel.rb:38:in `require'
     1: from /opt/thedeployer/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/zeitwerk-2.6.12/lib/zeitwerk/kernel.rb:38:in `require'
/opt/thedeployer/pangea.rewardops.net/releases/20240129183011Z/app/validation_schemas/override/cash_override/api/create_contract.rb:1:in `<top (required)>': can't modify frozen Module (FrozenError)

At the end you can see this line:

/opt/thedeployer/pangea.rewardops.net/releases/20240129183011Z/app/validation_schemas/override/cash_override/api/create_contract.rb:1:in `<top (required)>': can't modify frozen Module (FrozenError)

It is poitning to this file:

class Override::CashOverride::Api::CreateContract < AppContract
  # dry-validations file
  # validation code below...
  # ...
end

We are in the process of upgrading dry-validations gem from 0.13.x to 1.x version, this is one of the files I refactored...

for now the only thing I could do to prevent this error from happening is to change this setting in our environment file config/environments/qa.rb:

# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both thread web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = false

I changed it from true to false and the app started to work, this is a temporal solution but would like to know why it works when I change this setting?

In prod we have this setting set to true and I think we can't just merge this dry-validations upgrade branch with that setting set to false that would break things in prod or cause other side effects, but Im not sure about those side effects.

Update

Adding more details about the file listed in the Traceback app/validation_schemas/override/cash_override/api/create_contract.rb, it is a validation contract defined as class Override::CashOverride::Api::CreateContract that inherits from AppContract located at app/validation_schemas/app_contract.rb which is defined as follows:

class AppContract < Dry::Validation::Contract
  # dry-validations options and configs defined here
  # a bunch of methods used in contracts
  # ...
end
0

There are 0 answers