Please sign in to comment.
Have the connection pool remove disconnected connections when the ada…
…pter supports it This adds a Sequel::DatabaseDisconnectError (subclass of Sequel::DatabaseError), for signaling to the connection pool that the connection was lost. It changes the connection pool code to rescue that exception and remove the offending connection from the connection pool. In order to implement this, a disconnection_proc had to be added to the connection pool. Sequel uses a generic one that calls Database#disconnect_connection. disconnection_proc is called both when connections are removed because the connection was lost and when Database#disconnect is called. Database#disconnect now calls @pool.disconnect, which now uses the disconnection_proc if no block is provided. All adapters have been modified to remove Database#disconnect and define Database#disconnect_connection, which was fairly easy since all defined #disconnect methods just called @pool.disconnect with a block that disconnected each connection. The only adapter that currently supports this is PostgreSQL. The PostgreSQL adapter used to silently attempt to reconnect, which might have caused the same SQL to be used twice. I'm not sure it could have happened, but I'm not sure it couldn't have happened either. Now, if the database connection is lost, it raises DatabaseDisconnectError, the connection pool removes the connection from the pool, and raises the error to the application. If the application wants to continue, it can always retry. While mucking in the connection pool, I found a bug where the wrong key could be used when new connections were created. This wasn't a huge issue in most cases, but it could have caused as many as twice the number of max_connections connections to be created.
- Loading branch information...
Showing with 162 additions and 84 deletions.
- +2 −0 CHANGELOG
- +6 −4 lib/sequel_core/adapters/ado.rb
- +8 −10 lib/sequel_core/adapters/db2.rb
- +6 −4 lib/sequel_core/adapters/dbi.rb
- +6 −4 lib/sequel_core/adapters/informix.rb
- +5 −5 lib/sequel_core/adapters/jdbc.rb
- +5 −5 lib/sequel_core/adapters/mysql.rb
- +5 −4 lib/sequel_core/adapters/odbc.rb
- +6 −5 lib/sequel_core/adapters/openbase.rb
- +6 −4 lib/sequel_core/adapters/oracle.rb
- +16 −10 lib/sequel_core/adapters/postgres.rb
- +5 −5 lib/sequel_core/adapters/sqlite.rb
- +47 −13 lib/sequel_core/connection_pool.rb
- +7 −4 lib/sequel_core/database.rb
- +6 −0 lib/sequel_core/exceptions.rb
- +26 −1 spec/sequel_core/connection_pool_spec.rb
- +0 −6 spec/sequel_core/database_spec.rb
Oops, something went wrong.