{"push_id":584024841,"size":2,"distinct_size":1,"ref":"refs/heads/hhsu/fix_stale_connections_redux","head":"7e6343f190ce267291efc5597d741f0ba936bb79","before":"1284dbee999c57acbc7e6bb5e4f35f3984c4fc0d","commits":[{"sha":"fbad2d74ffbc092111c197d9ac0718982b97ab6f","author":{"email":"73675debcd8a436be48ec22211dcf44fe0df0a64@zendesk.com","name":"Ben Osheroff"},"message":"fix gemspec","distinct":false,"url":"https://api.github.com/repos/zendesk/active_record_host_pool/commits/fbad2d74ffbc092111c197d9ac0718982b97ab6f"},{"sha":"7e6343f190ce267291efc5597d741f0ba936bb79","author":{"email":"71f53521317aa9a65c30aacb83af64c6c7edb8a6@zendesk.com","name":"Henry Hsu"},"message":"Redux: Ensures invalid connections are not re-used\n\nTurns out my test didn't completely exercise the code the same way `rake\ndb:reset` exercises the code. Here's why the test was inadequate:\n\n1. It runs `TestNotThere.establish_connection` followed by\n`TestNotThere.connection`, which properly removes the invalid connection\nto `arhp_test_no_create` from the connection pool.\n2. Then it runs `Test1.establish_connection(:test_host_1_db_1)`\n(database: `arhp_test_1`).\n3. This invokes\nhttps://github.com/rails/rails/blob/v3.2.21/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb#L136\n4. Which invokes\nhttps://github.com/rails/rails/blob/v3.2.21/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb#L429\n5. Which invokes self.__getobj__ https://github.com/zendesk/active_record_host_pool/blob/master/lib/active_record_host_pool/pool_proxy.rb#L21\n6. Which re-instantiates the connection pool with the original spec: https://github.com/zendesk/active_record_host_pool/blob/master/lib/active_record_host_pool/pool_proxy.rb#L104\n7. Which stores an invalid connection to `arhp_test_1`.\n8. And as expected, when it runs `Test1.connection`, it gets an `Unknown\ndatabase 'arhp_test_1'` exception.\n\nAnd here is where the use case breaks down:\n\n1. It runs `TestNotThere.establish_connection` followed by\n`TestNotThere.connection`, which properly removes the invalid connection\nto `arhp_test_no_create` from the connection pool.\n2. Then it runs `TestNotThere.establish_connection(:test_host_1_db_1)`\n(database: `arhp_test_1`).\n3. This invokes\nhttps://github.com/rails/rails/blob/v3.2.21/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb#L136\n4. Which invokes\nhttps://github.com/rails/rails/blob/v3.2.21/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb#L429\n5. Which invokes self.__getobj__ https://github.com/zendesk/active_record_host_pool/blob/master/lib/active_record_host_pool/pool_proxy.rb#L21\n6. Which re-instantiates the connection pool with the original spec: https://github.com/zendesk/active_record_host_pool/blob/master/lib/active_record_host_pool/pool_proxy.rb#L104\n7. Which stores an invalid connection to `arhp_test_no_create` (the\nconnection from 1)\n8. And when it runs `TestNotThere.connection`, it gets an `Unknown\ndatabase 'arhp_test_no_create'` exception.\n\nIn conclusion, this PR will get us past the problem. Though, in all\nseriousness, the way if there is an invalid connection and we manage to\nhit an undefined method in `PoolProxy`, we will store that invalid\nconnection. It seems a longer term fix would be to check for connection\nvalidity prior to storing/retrieving a connection.","distinct":true,"url":"https://api.github.com/repos/zendesk/active_record_host_pool/commits/7e6343f190ce267291efc5597d741f0ba936bb79"}]}