Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Database connection required while loading the code on 1.10.x #291

Closed
morgoth opened this issue Jul 5, 2021 · 3 comments · Fixed by #293
Closed

Database connection required while loading the code on 1.10.x #291

morgoth opened this issue Jul 5, 2021 · 3 comments · Fixed by #293

Comments

@morgoth
Copy link
Collaborator

morgoth commented Jul 5, 2021

In one of our applications, our building process is containerized.
During image build we precompile assets, thus we load the application environment (as this is how Rails is doing this task).
We do not provide database connection, as it is not needed.
However in latest update, the GJ requires a connection to database while loading the code.

/usr/local/bundle/gems/activerecord-6.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:83:in `rescue in new_client': could not connect to server: No such file or directory (ActiveRecord::ConnectionNotEstablished)
	Is the server running locally and accepting
	connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
	from /usr/local/bundle/gems/activerecord-6.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:77:in `new_client'
	from /usr/local/bundle/gems/activerecord-6.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:37:in `postgresql_connection'
	from /usr/local/bundle/gems/activerecord-6.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `public_send'
	from /usr/local/bundle/gems/activerecord-6.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `new_connection'
	from /usr/local/bundle/gems/activerecord-6.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:926:in `checkout_new_connection'
	from /usr/local/bundle/gems/activerecord-6.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:905:in `try_to_checkout_new_connection'
	from /usr/local/bundle/gems/activerecord-6.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:866:in `acquire_connection'
	from /usr/local/bundle/gems/activerecord-6.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:588:in `checkout'
	from /usr/local/bundle/gems/activerecord-6.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:428:in `connection'
	from /usr/local/bundle/gems/activerecord-6.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:1128:in `retrieve_connection'
	from /usr/local/bundle/gems/activerecord-6.1.4/lib/active_record/connection_handling.rb:327:in `retrieve_connection'
	from /usr/local/bundle/gems/activerecord-6.1.4/lib/active_record/connection_handling.rb:283:in `connection'
	from /usr/local/bundle/gems/activerecord-6.1.4/lib/active_record/model_schema.rb:380:in `table_exists?'
	from /usr/local/bundle/gems/activerecord-6.1.4/lib/active_record/attribute_methods/primary_key.rb:95:in `get_primary_key'
	from /usr/local/bundle/gems/activerecord-6.1.4/lib/active_record/attribute_methods/primary_key.rb:83:in `reset_primary_key'
	from /usr/local/bundle/gems/activerecord-6.1.4/lib/active_record/attribute_methods/primary_key.rb:71:in `primary_key'
	from /usr/local/bundle/gems/good_job-1.10.1/lib/good_job/lockable.rb:26:in `block (2 levels) in <module:Lockable>'
	from /usr/local/bundle/gems/activesupport-6.1.4/lib/active_support/core_ext/module/attribute_accessors.rb:65:in `block in mattr_reader'
	from /usr/local/bundle/gems/activesupport-6.1.4/lib/active_support/core_ext/module/attribute_accessors.rb:56:in `each'
	from /usr/local/bundle/gems/activesupport-6.1.4/lib/active_support/core_ext/module/attribute_accessors.rb:56:in `mattr_reader'
	from /usr/local/bundle/gems/activesupport-6.1.4/lib/active_support/core_ext/module/attribute_accessors.rb:202:in `mattr_accessor'
	from /usr/local/bundle/gems/good_job-1.10.1/lib/good_job/lockable.rb:26:in `block in <module:Lockable>'
	from /usr/local/bundle/gems/activesupport-6.1.4/lib/active_support/concern.rb:136:in `class_eval'
	from /usr/local/bundle/gems/activesupport-6.1.4/lib/active_support/concern.rb:136:in `append_features'
	from /usr/local/bundle/gems/good_job-1.10.1/lib/good_job/job.rb:7:in `include'
	from /usr/local/bundle/gems/good_job-1.10.1/lib/good_job/job.rb:7:in `<class:Job>'
	from /usr/local/bundle/gems/good_job-1.10.1/lib/good_job/job.rb:6:in `<module:GoodJob>'
	from /usr/local/bundle/gems/good_job-1.10.1/lib/good_job/job.rb:1:in `<main>'
	from /usr/local/bundle/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
	from /usr/local/bundle/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
	from /usr/local/bundle/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
	from /usr/local/bundle/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
	from /usr/local/bundle/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
	from /usr/local/bundle/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:26:in `require'
	from /usr/local/bundle/gems/zeitwerk-2.4.2/lib/zeitwerk/loader.rb:409:in `const_get'
	from /usr/local/bundle/gems/zeitwerk-2.4.2/lib/zeitwerk/loader.rb:409:in `block (2 levels) in eager_load'
	from /usr/local/bundle/gems/zeitwerk-2.4.2/lib/zeitwerk/loader.rb:733:in `block in ls'
	from /usr/local/bundle/gems/zeitwerk-2.4.2/lib/zeitwerk/loader.rb:725:in `foreach'
	from /usr/local/bundle/gems/zeitwerk-2.4.2/lib/zeitwerk/loader.rb:725:in `ls'
	from /usr/local/bundle/gems/zeitwerk-2.4.2/lib/zeitwerk/loader.rb:404:in `block in eager_load'
	from /usr/local/bundle/gems/zeitwerk-2.4.2/lib/zeitwerk/loader.rb:393:in `synchronize'
	from /usr/local/bundle/gems/zeitwerk-2.4.2/lib/zeitwerk/loader.rb:393:in `eager_load'
	from /usr/local/bundle/gems/zeitwerk-2.4.2/lib/zeitwerk/loader.rb:508:in `each'
	from /usr/local/bundle/gems/zeitwerk-2.4.2/lib/zeitwerk/loader.rb:508:in `eager_load_all'
	from /usr/local/bundle/gems/railties-6.1.4/lib/rails/application/finisher.rb:133:in `block in <module:Finisher>'
	from /usr/local/bundle/gems/railties-6.1.4/lib/rails/initializable.rb:32:in `instance_exec'
	from /usr/local/bundle/gems/railties-6.1.4/lib/rails/initializable.rb:32:in `run'
	from /usr/local/bundle/gems/railties-6.1.4/lib/rails/initializable.rb:61:in `block in run_initializers'
	from /usr/local/lib/ruby/3.0.0/tsort.rb:228:in `block in tsort_each'
	from /usr/local/lib/ruby/3.0.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
	from /usr/local/lib/ruby/3.0.0/tsort.rb:431:in `each_strongly_connected_component_from'
	from /usr/local/lib/ruby/3.0.0/tsort.rb:349:in `block in each_strongly_connected_component'
	from /usr/local/lib/ruby/3.0.0/tsort.rb:347:in `each'
	from /usr/local/lib/ruby/3.0.0/tsort.rb:347:in `call'
	from /usr/local/lib/ruby/3.0.0/tsort.rb:347:in `each_strongly_connected_component'
	from /usr/local/lib/ruby/3.0.0/tsort.rb:226:in `tsort_each'
	from /usr/local/lib/ruby/3.0.0/tsort.rb:205:in `tsort_each'
	from /usr/local/bundle/gems/railties-6.1.4/lib/rails/initializable.rb:60:in `run_initializers'
	from /usr/local/bundle/gems/railties-6.1.4/lib/rails/application.rb:391:in `initialize!'
	from /home/app/code/config/environment.rb:7:in `<main>'
	from /usr/local/bundle/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
	from /usr/local/bundle/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
	from /usr/local/bundle/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
	from /usr/local/bundle/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
	from /usr/local/bundle/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
	from /usr/local/bundle/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34:in `require'
	from /usr/local/bundle/gems/activesupport-6.1.4/lib/active_support/dependencies.rb:332:in `block in require'
	from /usr/local/bundle/gems/activesupport-6.1.4/lib/active_support/dependencies.rb:299:in `load_dependency'
	from /usr/local/bundle/gems/activesupport-6.1.4/lib/active_support/dependencies.rb:332:in `require'
	from /usr/local/bundle/gems/railties-6.1.4/lib/rails/application.rb:367:in `require_environment!'
	from /usr/local/bundle/gems/railties-6.1.4/lib/rails/command/actions.rb:28:in `require_environment!'
	from /usr/local/bundle/gems/railties-6.1.4/lib/rails/command/actions.rb:15:in `require_application_and_environment!'
	from /usr/local/bundle/gems/railties-6.1.4/lib/rails/commands/runner/runner_command.rb:33:in `perform'
	from /usr/local/bundle/gems/thor-1.1.0/lib/thor/command.rb:27:in `run'
	from /usr/local/bundle/gems/thor-1.1.0/lib/thor/invocation.rb:127:in `invoke_command'
	from /usr/local/bundle/gems/thor-1.1.0/lib/thor.rb:392:in `dispatch'
	from /usr/local/bundle/gems/railties-6.1.4/lib/rails/command/base.rb:69:in `perform'
	from /usr/local/bundle/gems/railties-6.1.4/lib/rails/command.rb:48:in `invoke'
	from /usr/local/bundle/gems/railties-6.1.4/lib/rails/commands.rb:18:in `<main>'
	from /usr/local/bundle/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
	from /usr/local/bundle/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
	from /usr/local/bundle/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
	from /usr/local/bundle/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
	from /usr/local/bundle/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
	from bin/rails:5:in `<main>'

Reading a primary key is a problem here https://github.com/bensheldon/good_job/blob/main/lib/good_job/lockable.rb#L26

Is it possible to somehow lazy load it?

@bensheldon
Copy link
Owner

Yikes! Yes, the value can be deferred. I also think that should be a class_attribute, which has a slightly different API.

@bensheldon
Copy link
Owner

@morgoth I have a fix for this in just released v1.11.1. Thank you 🙏

@morgoth
Copy link
Collaborator Author

morgoth commented Jul 8, 2021

Now the deployment went fine. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants