Closed benjaminwols closed 6 years ago
Thank you for your telling. I've tried. But it doesn't occur the exception.
$ bundle exec rails c
Loading production environment (Rails 5.1.6)
irb(main):002:0> Article.take
[replica] Article Load (0.9ms) SELECT "articles".* FROM "articles" LIMIT $1 [["LIMIT", 1]]
=> #<Article id: 1, title: "sushi", body: "I like it", created_at: "2018-06-22 13:27:41", updated_at: "2018-06-22 13:27:41">
irb(main):003:0> c = Article.connection
=> #<ActiveRecord::ConnectionAdapters::PostgreSQLAdapter:0x00007fdda01500d8....>
irb(main):004:0> c.model_class = :hoge
=> :hoge
irb(main):005:0> c.method(:model_class=).source_location
=> ["/Users/tsukasa/dev/tsu/.bundle/ruby/2.5.0/gems/fresh_connection-3.0.0/lib/fresh_connection/extend/ar_abstract_adapter.rb", 23]
Please teach me detail the situation to occur the exception. (Sample code, Using other gems, etc)
The problem only occurs in the server and not in the console. It also only happens on our staging (linux) environment and not in development (macOS). I'll investigate further and let you know if I can reproduce the error.
Could you tell me the backtrace when the exception occurs?
Here is the backtrace:
fresh_connection (3.0.0) lib/fresh_connection/extend/ar_base.rb:21:in `block in connection'
fresh_connection (3.0.0) lib/fresh_connection/extend/ar_base.rb:21:in `tap'
fresh_connection (3.0.0) lib/fresh_connection/extend/ar_base.rb:21:in `connection'
activerecord (5.1.6) lib/active_record/model_schema.rb:434:in `reset_column_information'
activerecord-session_store (1.1.1) lib/active_record/session_store/session.rb:46:in `setup_sessid_compatibility!'
activerecord-session_store (1.1.1) lib/active_record/session_store/session.rb:34:in `block in find_by_session_id'
activerecord-session_store (1.1.1) lib/active_record/session_store/session.rb:34:in `synchronize'
activerecord-session_store (1.1.1) lib/active_record/session_store/session.rb:34:in `find_by_session_id'
activerecord-session_store (1.1.1) lib/action_dispatch/session/active_record_store.rb:124:in `block in get_session_model'
activerecord-session_store (1.1.1) lib/active_record/session_store/extension/logger_silencer.rb:47:in `silence_logger'
activerecord-session_store (1.1.1) lib/action_dispatch/session/active_record_store.rb:123:in `get_session_model'
activerecord-session_store (1.1.1) lib/action_dispatch/session/active_record_store.rb:140:in `find_session'
rack (2.0.5) lib/rack/session/abstract/id.rb:280:in `load_session'
actionpack (5.1.6) lib/action_dispatch/middleware/session/abstract_store.rb:44:in `block in load_session'
actionpack (5.1.6) lib/action_dispatch/middleware/session/abstract_store.rb:52:in `stale_session_check!'
actionpack (5.1.6) lib/action_dispatch/middleware/session/abstract_store.rb:44:in `load_session'
actionpack (5.1.6) lib/action_dispatch/request/session.rb:216:in `load!'
actionpack (5.1.6) lib/action_dispatch/request/session.rb:208:in `load_for_read!'
actionpack (5.1.6) lib/action_dispatch/request/session.rb:90:in `[]'
warden (1.2.7) lib/warden/session_serializer.rb:31:in `fetch'
warden (1.2.7) lib/warden/proxy.rb:213:in `user'
warden (1.2.7) lib/warden/proxy.rb:323:in `_perform_authentication'
warden (1.2.7) lib/warden/proxy.rb:105:in `authenticate'
warden (1.2.7) lib/warden/proxy.rb:115:in `authenticate?'
devise (4.4.3) lib/devise/controllers/sign_in_out.rb:15:in `block in signed_in?'
devise (4.4.3) lib/devise/controllers/sign_in_out.rb:14:in `any?'
devise (4.4.3) lib/devise/controllers/sign_in_out.rb:14:in `signed_in?'
/home/ubuntu/.rvm/gems/ruby-2.5.1@ans/bundler/gems/two_factor_authentication-861b242c356e/lib/two_factor_authentication/controllers/helpers.rb:15:in `block in handle_two_factor_authentication'
/home/ubuntu/.rvm/gems/ruby-2.5.1@ans/bundler/gems/two_factor_authentication-861b242c356e/lib/two_factor_authentication/controllers/helpers.rb:14:in `any?'
/home/ubuntu/.rvm/gems/ruby-2.5.1@ans/bundler/gems/two_factor_authentication-861b242c356e/lib/two_factor_authentication/controllers/helpers.rb:14:in `handle_two_factor_authentication'
activesupport (5.1.6) lib/active_support/callbacks.rb:413:in `block in make_lambda'
activesupport (5.1.6) lib/active_support/callbacks.rb:197:in `block (2 levels) in halting'
actionpack (5.1.6) lib/abstract_controller/callbacks.rb:12:in `block (2 levels) in <module:Callbacks>'
activesupport (5.1.6) lib/active_support/callbacks.rb:198:in `block in halting'
activesupport (5.1.6) lib/active_support/callbacks.rb:507:in `block in invoke_before'
activesupport (5.1.6) lib/active_support/callbacks.rb:507:in `each'
activesupport (5.1.6) lib/active_support/callbacks.rb:507:in `invoke_before'
activesupport (5.1.6) lib/active_support/callbacks.rb:130:in `run_callbacks'
actionpack (5.1.6) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (5.1.6) lib/action_controller/metal/rescue.rb:20:in `process_action'
actionpack (5.1.6) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
appsignal (2.5.3) lib/appsignal/hooks/active_support_notifications.rb:19:in `block in instrument'
activesupport (5.1.6) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
appsignal (2.5.3) lib/appsignal/hooks/active_support_notifications.rb:36:in `instrument'
appsignal (2.5.3) lib/appsignal/hooks/active_support_notifications.rb:18:in `instrument'
actionpack (5.1.6) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (5.1.6) lib/action_controller/metal/params_wrapper.rb:252:in `process_action'
activerecord (5.1.6) lib/active_record/railties/controller_runtime.rb:22:in `process_action'
actionpack (5.1.6) lib/abstract_controller/base.rb:124:in `process'
actionview (5.1.6) lib/action_view/rendering.rb:30:in `process'
actionpack (5.1.6) lib/action_controller/metal.rb:189:in `dispatch'
actionpack (5.1.6) lib/action_controller/metal.rb:253:in `dispatch'
actionpack (5.1.6) lib/action_dispatch/routing/route_set.rb:49:in `dispatch'
actionpack (5.1.6) lib/action_dispatch/routing/route_set.rb:31:in `serve'
actionpack (5.1.6) lib/action_dispatch/journey/router.rb:50:in `block in serve'
actionpack (5.1.6) lib/action_dispatch/journey/router.rb:33:in `each'
actionpack (5.1.6) lib/action_dispatch/journey/router.rb:33:in `serve'
actionpack (5.1.6) lib/action_dispatch/routing/route_set.rb:844:in `call'
remotipart (1.4.2) lib/remotipart/middleware.rb:32:in `call'
warden (1.2.7) lib/warden/manager.rb:36:in `block in call'
warden (1.2.7) lib/warden/manager.rb:35:in `catch'
warden (1.2.7) lib/warden/manager.rb:35:in `call'
rack (2.0.5) lib/rack/etag.rb:25:in `call'
rack (2.0.5) lib/rack/conditional_get.rb:25:in `call'
rack (2.0.5) lib/rack/head.rb:12:in `call'
rack (2.0.5) lib/rack/session/abstract/id.rb:232:in `context'
rack (2.0.5) lib/rack/session/abstract/id.rb:226:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/cookies.rb:613:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/callbacks.rb:26:in `block in call'
activesupport (5.1.6) lib/active_support/callbacks.rb:97:in `run_callbacks'
actionpack (5.1.6) lib/action_dispatch/middleware/callbacks.rb:24:in `call'
appsignal (2.5.3) lib/appsignal/rack/rails_instrumentation.rb:30:in `call_with_appsignal_monitoring'
appsignal (2.5.3) lib/appsignal/rack/rails_instrumentation.rb:15:in `call'
appsignal (2.5.3) lib/appsignal/rack/js_exception_catcher.rb:32:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/debug_exceptions.rb:59:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
railties (5.1.6) lib/rails/rack/logger.rb:36:in `call_app'
railties (5.1.6) lib/rails/rack/logger.rb:24:in `block in call'
activesupport (5.1.6) lib/active_support/tagged_logging.rb:69:in `block in tagged'
activesupport (5.1.6) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (5.1.6) lib/active_support/tagged_logging.rb:69:in `tagged'
railties (5.1.6) lib/rails/rack/logger.rb:24:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
request_store (1.4.1) lib/request_store/middleware.rb:19:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/request_id.rb:25:in `call'
rack (2.0.5) lib/rack/method_override.rb:22:in `call'
rack (2.0.5) lib/rack/runtime.rb:22:in `call'
activesupport (5.1.6) lib/active_support/cache/strategy/local_cache_middleware.rb:27:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/executor.rb:12:in `call'
rack (2.0.5) lib/rack/sendfile.rb:111:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/ssl.rb:68:in `call'
railties (5.1.6) lib/rails/engine.rb:522:in `call'
puma (3.11.4) lib/puma/configuration.rb:225:in `call'
puma (3.11.4) lib/puma/server.rb:632:in `handle_request'
puma (3.11.4) lib/puma/server.rb:446:in `process_client'
puma (3.11.4) lib/puma/server.rb:306:in `block in run'
puma (3.11.4) lib/puma/thread_pool.rb:120:in `block in spawn_thread'
Thank you for the backtrace!
I think that it is caused by using inherited
method to extend Adapter.
I will fix this exception, please give me a moment.
I fixed this problem (#26).
I released the version 3.0.1.rc2
.
Could you please check if the problem is resolved?
If it resolved I will release the version '3.0.1'.
This does indeed fix the problem. Thank you very much for this quick fix :) I'll close this issue.
There seems to be another problem. After a while I get this error: "FATAL: sorry, too many clients already"
It seems fresh_connection opens a new connection to the database for every request.
pg (0.21.0) lib/pg.rb:56:in `initialize'
pg (0.21.0) lib/pg.rb:56:in `new'
pg (0.21.0) lib/pg.rb:56:in `connect'
activerecord (5.1.6) lib/active_record/connection_adapters/postgresql_adapter.rb:697:in `connect'
activerecord (5.1.6) lib/active_record/connection_adapters/postgresql_adapter.rb:221:in `initialize'
activerecord (5.1.6) lib/active_record/connection_adapters/postgresql_adapter.rb:38:in `new'
activerecord (5.1.6) lib/active_record/connection_adapters/postgresql_adapter.rb:38:in `postgresql_connection'
activerecord (5.1.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:759:in `new_connection'
activerecord (5.1.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:803:in `checkout_new_connection'
activerecord (5.1.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:782:in `try_to_checkout_new_connection'
activerecord (5.1.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:743:in `acquire_connection'
activerecord (5.1.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:500:in `checkout'
activerecord (5.1.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:374:in `connection'
fresh_connection (3.0.1.rc2) lib/fresh_connection/connection_manager.rb:15:in `replica_connection'
fresh_connection (3.0.1.rc2) lib/fresh_connection/replica_connection_handler.rb:24:in `connection'
fresh_connection (3.0.1.rc2) lib/fresh_connection/extend/ar_base.rb:25:in `replica_connection'
fresh_connection (3.0.1.rc2) lib/fresh_connection/extend/adapters/pg_adapter.rb:15:in `__change_connection'
fresh_connection (3.0.1.rc2) lib/fresh_connection/extend/adapters/base_adapter.rb:20:in `select_value'
activerecord (5.1.6) lib/active_record/relation/finder_methods.rb:319:in `exists?'
fresh_connection (3.0.1.rc2) lib/fresh_connection/extend/ar_relation.rb:11:in `block in exists?'
fresh_connection (3.0.1.rc2) lib/fresh_connection/access_control.rb:45:in `switch_to'
fresh_connection (3.0.1.rc2) lib/fresh_connection/access_control.rb:39:in `access'
fresh_connection (3.0.1.rc2) lib/fresh_connection/access_control.rb:14:in `manage_access'
fresh_connection (3.0.1.rc2) lib/fresh_connection/extend/ar_relation.rb:37:in `manage_access'
fresh_connection (3.0.1.rc2) lib/fresh_connection/extend/ar_relation.rb:11:in `exists?'
app/helpers/application_helper.rb:54:in `python_server_status'
app/controllers/home_controller.rb:54:in `server_status'
actionpack (5.1.6) lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'
actionpack (5.1.6) lib/abstract_controller/base.rb:186:in `process_action'
actionpack (5.1.6) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (5.1.6) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (5.1.6) lib/active_support/callbacks.rb:131:in `run_callbacks'
actionpack (5.1.6) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (5.1.6) lib/action_controller/metal/rescue.rb:20:in `process_action'
actionpack (5.1.6) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
appsignal (2.5.3) lib/appsignal/hooks/active_support_notifications.rb:19:in `block in instrument'
activesupport (5.1.6) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
appsignal (2.5.3) lib/appsignal/hooks/active_support_notifications.rb:36:in `instrument'
appsignal (2.5.3) lib/appsignal/hooks/active_support_notifications.rb:18:in `instrument'
actionpack (5.1.6) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (5.1.6) lib/action_controller/metal/params_wrapper.rb:252:in `process_action'
activerecord (5.1.6) lib/active_record/railties/controller_runtime.rb:22:in `process_action'
actionpack (5.1.6) lib/abstract_controller/base.rb:124:in `process'
actionview (5.1.6) lib/action_view/rendering.rb:30:in `process'
actionpack (5.1.6) lib/action_controller/metal.rb:189:in `dispatch'
actionpack (5.1.6) lib/action_controller/metal.rb:253:in `dispatch'
actionpack (5.1.6) lib/action_dispatch/routing/route_set.rb:49:in `dispatch'
actionpack (5.1.6) lib/action_dispatch/routing/route_set.rb:31:in `serve'
actionpack (5.1.6) lib/action_dispatch/journey/router.rb:50:in `block in serve'
actionpack (5.1.6) lib/action_dispatch/journey/router.rb:33:in `each'
actionpack (5.1.6) lib/action_dispatch/journey/router.rb:33:in `serve'
actionpack (5.1.6) lib/action_dispatch/routing/route_set.rb:844:in `call'
remotipart (1.4.2) lib/remotipart/middleware.rb:32:in `call'
warden (1.2.7) lib/warden/manager.rb:36:in `block in call'
warden (1.2.7) lib/warden/manager.rb:35:in `catch'
warden (1.2.7) lib/warden/manager.rb:35:in `call'
rack (2.0.5) lib/rack/etag.rb:25:in `call'
rack (2.0.5) lib/rack/conditional_get.rb:25:in `call'
rack (2.0.5) lib/rack/head.rb:12:in `call'
rack (2.0.5) lib/rack/session/abstract/id.rb:232:in `context'
rack (2.0.5) lib/rack/session/abstract/id.rb:226:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/cookies.rb:613:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/callbacks.rb:26:in `block in call'
activesupport (5.1.6) lib/active_support/callbacks.rb:97:in `run_callbacks'
actionpack (5.1.6) lib/action_dispatch/middleware/callbacks.rb:24:in `call'
appsignal (2.5.3) lib/appsignal/rack/rails_instrumentation.rb:30:in `call_with_appsignal_monitoring'
appsignal (2.5.3) lib/appsignal/rack/rails_instrumentation.rb:15:in `call'
appsignal (2.5.3) lib/appsignal/rack/js_exception_catcher.rb:32:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/debug_exceptions.rb:59:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
railties (5.1.6) lib/rails/rack/logger.rb:36:in `call_app'
railties (5.1.6) lib/rails/rack/logger.rb:24:in `block in call'
activesupport (5.1.6) lib/active_support/tagged_logging.rb:69:in `block in tagged'
activesupport (5.1.6) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (5.1.6) lib/active_support/tagged_logging.rb:69:in `tagged'
railties (5.1.6) lib/rails/rack/logger.rb:24:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
request_store (1.4.1) lib/request_store/middleware.rb:19:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/request_id.rb:25:in `call'
rack (2.0.5) lib/rack/method_override.rb:22:in `call'
rack (2.0.5) lib/rack/runtime.rb:22:in `call'
activesupport (5.1.6) lib/active_support/cache/strategy/local_cache_middleware.rb:27:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/executor.rb:12:in `call'
rack (2.0.5) lib/rack/sendfile.rb:111:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/ssl.rb:68:in `call'
railties (5.1.6) lib/rails/engine.rb:522:in `call'
puma (3.11.4) lib/puma/configuration.rb:225:in `call'
puma (3.11.4) lib/puma/server.rb:632:in `handle_request'
puma (3.11.4) lib/puma/server.rb:446:in `process_client'
puma (3.11.4) lib/puma/server.rb:306:in `block in run'
puma (3.11.4) lib/puma/thread_pool.rb:120:in `block in spawn_thread'
I will check. Please wait a couple of days.
I fixed this terrible problem(#27).
I released the fix version 3.0.2
.
Could you please check if the problem is resolved?
I have been running version 3.0.2 for 2 days now on our staging environment and I haven't found any new issues, so I will close this issue. Thanks for the quick fix!
Thank you for your check!
Hi @tsukasaoishi, I'm not able to use the latest version of your gem (still stuck on rails 4.2). Is there a way to patch the gem to have this fix? Or 2.4.x is not affected by this?
@mr-sudaca Yes. 2.4.x is not affected by this issue.
With version 3.0 I get the following error: NoMethodError (undefined method `model_class=' for #)
I have following gem versions gem 'rails', '5.1.6' gem 'pg', '~> 0.21'
I downgraded to version 2.4.4 and the problem was resolved.