Repository navigation
Improve AR connection fork safety - #31173
Conversation
There was a problem hiding this comment.
Hi, I'm testing this pull request with Oracle enhanced adapter to see how to implement discard! method. As of right now what I can say is Oracle database always need from for every select statement.
ActiveRecord::StatementInvalid: OCIError: ORA-00923: FROM keyword not found where expected: SELECT 2 + 3
Would you consider this so that all bundled + Oracle enhanced adapter can support this test?
There was a problem hiding this comment.
Sure! I'll look through existing tests for a better idea of a query to run.
I initially used #active?, but that just returned false when the test failed (i.e., without the corresponding change), and I wanted to see the actual "connection is broken / server has gone away" exception.
Use whatever adapter-provided means we have available to ensure forked children don't send quit/shutdown/goodbye messages to the server on connections that belonged to their parent.
919dc58 to
f32cff5
Compare
|
@matthewd nice! I guess we should remove from the default Puma template. |
This reverts commit f6d3993.
Since rails#31173, mysql2 adapter depends on `automatic_close` which is introduced since mysql2 0.4.3. So the adapter with the mysql2 version before doesn't work with fork now. ``` % ARCONN=mysql2 be ruby -w -Itest test/cases/connection_adapters/connection_handler_test.rb -n test_forked_child_doesnt_mangle_parent_connection Using mysql2 Run options: -n test_forked_child_doesnt_mangle_parent_connection --seed 19988 /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb:108:in `discard!': undefined method `automatic_close=' for #<Mysql2::Client:0x00007fedaa91dfd0> (NoMethodError) ``` This drops mysql2 version less than 0.4.3 to guarantee fork safety.
Since #31173, mysql2 adapter depends on `automatic_close` which is introduced since mysql2 0.4.3. So the adapter with the mysql2 version before doesn't work with fork now. ``` % ARCONN=mysql2 be ruby -w -Itest test/cases/connection_adapters/connection_handler_test.rb -n test_forked_child_doesnt_mangle_parent_connection Using mysql2 Run options: -n test_forked_child_doesnt_mangle_parent_connection --seed 19988 /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb:108:in `discard!': undefined method `automatic_close=' for #<Mysql2::Client:0x00007fedaa91dfd0> (NoMethodError) ``` This drops mysql2 version less than 0.4.3 to guarantee fork safety.
|
@matthewd May this be the cause that https://github.com/QueueClassic/queue_classic isn't working correctly since rails 5.2? See the line here: https://github.com/QueueClassic/queue_classic/blob/master/lib/queue_classic.rb#L55 Initially it works, but after a period of high(er) load, queue classic's initially passed |
New functionality was introduced in Rails 5.2 to ensure forked children don't send quit/shutdown/goodbye messages to the server on connections that belonged to their parent. See rails/rails#31173 for more information. We need to ensure that when the following line is called we also discard the pools we've cached. ActiveRecord::ConnectionAdapters:::ConnectionHandler.discard_unowned_pools Without this change, applications using this gem and Rails 5.2.3 will run into `NoMethodError (undefined method 'any?' for nil:NilClass)` exceptions from forked processes (e.g. Puma/Unicorn workers) since they'll be using the cached and discarded connection. The upshot of this change is we can do away with code like this: https://github.com/rails/rails/blob/c39ed435eb578c79867552c66da7eeb035fa58ad/railties/lib/rails/generators/rails/app/templates/config/puma.rb.tt#L35-L53
New functionality was introduced in Rails 5.2 to ensure forked children don't send quit/shutdown/goodbye messages to the server on connections that belonged to their parent. See rails/rails#31173 for more information. We need to ensure that when the following line is called we also discard the pools we've cached. ActiveRecord::ConnectionAdapters:::ConnectionHandler.discard_unowned_pools Without this change, applications using this gem and Rails 5.2.3 will run into `NoMethodError (undefined method 'any?' for nil:NilClass)` exceptions from forked processes (e.g. Puma/Unicorn workers) since they'll be using the cached and discarded connection. The upshot of this change is we can do away with code like this: https://github.com/rails/rails/blob/c39ed435eb578c79867552c66da7eeb035fa58ad/railties/lib/rails/generators/rails/app/templates/config/puma.rb.tt#L35-L53
New functionality was introduced in Rails 5.2 to ensure forked children don't send quit/shutdown/goodbye messages to the server on connections that belonged to their parent. See rails/rails#31173 for more information. We need to ensure that when the following line is called we also discard the pools we've cached. ActiveRecord::ConnectionAdapters:::ConnectionHandler.discard_unowned_pools Without this change, applications using this gem and Rails 5.2.3 will run into `NoMethodError (undefined method 'any?' for nil:NilClass)` exceptions from forked processes (e.g. Puma/Unicorn workers) since they'll be using the cached and discarded connection. The upshot of this change is we can do away with code like this: https://github.com/rails/rails/blob/c39ed435eb578c79867552c66da7eeb035fa58ad/railties/lib/rails/generators/rails/app/templates/config/puma.rb.tt#L35-L53
New functionality was introduced in Rails 5.2 to ensure forked children don't send quit/shutdown/goodbye messages to the server on connections that belonged to their parent. See rails/rails#31173 for more information. We need to ensure that when the following line is called we also discard the pools we've cached. ActiveRecord::ConnectionAdapters:::ConnectionHandler.discard_unowned_pools Without this change, applications using this gem and Rails 5.2.3 will run into `NoMethodError (undefined method 'any?' for nil:NilClass)` exceptions from forked processes (e.g. Puma/Unicorn workers) since they'll be using the cached and discarded connection. The upshot of this change is we can do away with code like this: https://github.com/rails/rails/blob/c39ed435eb578c79867552c66da7eeb035fa58ad/railties/lib/rails/generators/rails/app/templates/config/puma.rb.tt#L35-L53
New functionality was introduced in Rails 5.2 to ensure forked children don't send quit/shutdown/goodbye messages to the server on connections that belonged to their parent. See rails/rails#31173 for more information. We need to ensure that when the following line is called we also discard the pools we've cached. ActiveRecord::ConnectionAdapters:::ConnectionHandler.discard_unowned_pools Without this change, applications using this gem and Rails 5.2.3 will run into `NoMethodError (undefined method 'any?' for nil:NilClass)` exceptions from forked processes (e.g. Puma/Unicorn workers) since they'll be using the cached and discarded connection. The upshot of this change is we can do away with code like this: https://github.com/rails/rails/blob/c39ed435eb578c79867552c66da7eeb035fa58ad/railties/lib/rails/generators/rails/app/templates/config/puma.rb.tt#L35-L53
New functionality was introduced in Rails 5.2 to ensure forked children don't send quit/shutdown/goodbye messages to the server on connections that belonged to their parent. See rails/rails#31173 for more information. We need to ensure that when the following line is called we also discard the pools we've cached. ActiveRecord::ConnectionAdapters:::ConnectionHandler.discard_unowned_pools Without this change, applications using this gem and Rails 5.2.3 will run into `NoMethodError (undefined method 'any?' for nil:NilClass)` exceptions from forked processes (e.g. Puma/Unicorn workers) since they'll be using the cached and discarded connection. The upshot of this change is we can do away with code like this: https://github.com/rails/rails/blob/c39ed435eb578c79867552c66da7eeb035fa58ad/railties/lib/rails/generators/rails/app/templates/config/puma.rb.tt#L35-L53
New functionality was introduced in Rails 5.2 to ensure forked children don't send quit/shutdown/goodbye messages to the server on connections that belonged to their parent. See rails/rails#31173 for more information. We need to ensure that when the following line is called we also discard the pools we've cached. ActiveRecord::ConnectionAdapters:::ConnectionHandler.discard_unowned_pools Without this change, applications using this gem and Rails 5.2.3 will run into `NoMethodError (undefined method 'any?' for nil:NilClass)` exceptions from forked processes (e.g. Puma/Unicorn workers) since they'll be using the cached and discarded connection. The upshot of this change is we can do away with code like this: https://github.com/rails/rails/blob/c39ed435eb578c79867552c66da7eeb035fa58ad/railties/lib/rails/generators/rails/app/templates/config/puma.rb.tt#L35-L53
Use whatever adapter-provided means we have available to ensure forked children don't send quit/shutdown/goodbye messages to the server on connections that belonged to their parent.
socket_io, which is close enough.I believe this should eliminate the need for advice like this, along with much of what's currently described in #29807.