Comments (3)
Why is this a connection_pool issue?
On Oct 1, 2013, at 17:40, aldo sarmiento [email protected] wrote:
Hello, I've been noticing that connection_pool coupled with mperham's shared_connection strategy is leaving data in the DB.
I was able to add some logging in active_record/connection_adapters/abstract/database_statements.rb to produce the following output for one of my Selenium/Rails4/Rspec tests:
The issue:
- Near the bottom you'll see a ROLLBACK command. At this point, the Selenium thread issues a transaction begin BEGIN, but then seemingly checks in the connection before issuing a COMMIT.
- RSpec checks out the shared_connection and promptly issues a ROLLBACK (which adversely affects the previous BEGIN)
- RSpec then checks the shared_connection back in.
- Finally, the Selenium thread checks out the shared_connection and issues a COMMIT, saving instead of rolling back the test data.
RSpec Thread: 70184739145520
Selenium Server: 70184702836520
ARTransaction: BEGIN - Thread: 70184739145520 <<--- RSpec transaction to be rolled back after test
ARTransaction: BEGIN - Thread: 70184739145520 => ARTransaction: COMMIT - Thread: 70184739145520
ARTransaction: BEGIN - Thread: 70184739145520 => ARTransaction: COMMIT - Thread: 70184739145520
ARTransaction: BEGIN - Thread: 70184739145520 => ARTransaction: COMMIT - Thread: 70184739145520
ARTransaction: BEGIN - Thread: 70184739145520 => ARTransaction: COMMIT - Thread: 70184739145520
ARTransaction: BEGIN - Thread: 70184739145520 => ARTransaction: COMMIT - Thread: 70184739145520
ARTransaction: BEGIN - Thread: 70184739145520 => ARTransaction: COMMIT - Thread: 70184739145520
ARTransaction: BEGIN - Thread: 70184739145520 => ARTransaction: COMMIT - Thread: 70184739145520
ARTransaction: BEGIN - Thread: 70184739145520 => ARTransaction: COMMIT - Thread: 70184739145520
ARTransaction: BEGIN - Thread: 70184739145520 => ARTransaction: COMMIT - Thread: 70184739145520
ARTransaction: BEGIN - Thread: 70184739145520 => ARTransaction: COMMIT - Thread: 70184739145520
ARTransaction: BEGIN - Thread: 70184739145520 => ARTransaction: COMMIT - Thread: 70184739145520
ARTransaction: BEGIN - Thread: 70184739145520 => ARTransaction: COMMIT - Thread: 70184739145520
ARTransaction: BEGIN - Thread: 70184739145520 => ARTransaction: COMMIT - Thread: 70184739145520
ARTransaction: BEGIN - Thread: 70184739145520 => ARTransaction: COMMIT - Thread: 70184739145520
ARTransaction: BEGIN - Thread: 70184739145520 => ARTransaction: COMMIT - Thread: 70184739145520
ARTransaction: BEGIN - Thread: 70184739145520 => ARTransaction: COMMIT - Thread: 70184739145520
ARTransaction: BEGIN - Thread: 70184739145520 => ARTransaction: COMMIT - Thread: 70184739145520
ARTransaction: BEGIN - Thread: 70184739145520 => ARTransaction: COMMIT - Thread: 70184739145520
ARTransaction: BEGIN - Thread: 70184739145520 => ARTransaction: COMMIT - Thread: 70184739145520
ARTransaction: BEGIN - Thread: 70184739145520 => ARTransaction: COMMIT - Thread: 70184739145520
ARTransaction: BEGIN - Thread: 70184739145520 => ARTransaction: COMMIT - Thread: 70184739145520
ARTransaction: BEGIN - Thread: 70184739145520 => ARTransaction: COMMIT - Thread: 70184739145520
ARTransaction: BEGIN - Thread: 70184739145520 => ARTransaction: COMMIT - Thread: 70184739145520
ARTransaction: BEGIN - Thread: 70184739145520 => ARTransaction: COMMIT - Thread: 70184739145520
ARTransaction: BEGIN - Thread: 70184739145520 => ARTransaction: COMMIT - Thread: 70184739145520
ARTransaction: BEGIN - Thread: 70184739145520 => ARTransaction: COMMIT - Thread: 70184739145520
ARTransaction: BEGIN - Thread: 70184739145520 => ARTransaction: COMMIT - Thread: 70184739145520
ARTransaction: BEGIN - Thread: 70184739145520 => ARTransaction: COMMIT - Thread: 70184739145520
ARTransaction: BEGIN - Thread: 70184739145520 => ARTransaction: COMMIT - Thread: 70184739145520
ARTransaction: BEGIN - Thread: 70184702836520 => ARTransaction: COMMIT - Thread: 70184702836520
ARTransaction: BEGIN - Thread: 70184702836520 => ARTransaction: COMMIT - Thread: 70184702836520
ARTransaction: BEGIN - Thread: 70184702836520 => ARTransaction: COMMIT - Thread: 70184702836520
ARTransaction: BEGIN - Thread: 70184702836520 => ARTransaction: COMMIT - Thread: 70184702836520
ARTransaction: BEGIN - Thread: 70184702836520 => ARTransaction: COMMIT - Thread: 70184702836520
ARTransaction: BEGIN - Thread: 70184702836520 => ARTransaction: COMMIT - Thread: 70184702836520
ARTransaction: BEGIN - Thread: 70184702836520 => ARTransaction: COMMIT - Thread: 70184702836520
ARTransaction: BEGIN - Thread: 70184702836520 => ARTransaction: COMMIT - Thread: 70184702836520
ARTransaction: BEGIN - Thread: 70184702836520 => ARTransaction: COMMIT - Thread: 70184702836520
ARTransaction: BEGIN - Thread: 70184702836520 => ARTransaction: ROLLBACK - Thread: 70184739145520
ARTransaction: Commit - Thread: 70184702836520 <<-- Supposed to be RSpec rolling back everything
Mokey patched code to show logging:
active_record/connection_adapters/abstract/database_statements.rb
def begin_transaction(options = {}) #:nodoc: ::Rails::logger::info("# ARTransaction: Begin - Thread: #{Thread::current::object_id}") @transaction = @transaction.begin(options) end
def commit_transaction #:nodoc: ::Rails::logger::info("# ARTransaction: Commit - Thread: #{Thread::current::object_id}") @transaction = @transaction.commit end def rollback_transaction #:nodoc: ::Rails::logger::info("# ARTransaction: Rollback - Thread: #{Thread::current::object_id}") @transaction = @transaction.rollback end def reset_transaction #:nodoc: ::Rails::logger::info("# ARTransaction: Reset - Thread: #{Thread::current::object_id}") @transaction = ClosedTransaction.new(self) end
—
Reply to this email directly or view it on GitHub.
from connection_pool.
Well there's no repo for your gist: https://gist.github.com/mperham/3049152
And since this seems to be used in conjunction with shared_connection, I would assume this is a fair place to point out that sharing a connection w/ multiple threads has adverse effects even when using a mutex lock.
However, I must say that I've had a hard time figuring out where to post this. If you have a better suggestion, I would be happy to oblige.
from connection_pool.
@sarmiena I'd say post it in the gist itself—it does support comments and others are sharing problems there :)
That gist is indeed somewhat old. Maybe the fact that connection_pool
now supports reentrancy helps with the problem?
Anyway, closing this here. Thanks.
from connection_pool.
Related Issues (20)
- Connection Pool leaking connection object. HOT 3
- Inaccurate proxy behavior when a hash with String and Symbol keys is passed
- Support a "debug" mode HOT 2
- What does "connections should be self-repairing" mean? HOT 3
- Remove dependnecy on RubyGems HOT 11
- Observability for wait time, low water mark etc? HOT 2
- Automatic fork detection HOT 7
- Is the count correct? HOT 2
- Is it correct to cache this per-fiber? HOT 2
- Connections exceeding size of connection pool occasionally. HOT 2
- net_http_args nil class exception HOT 4
- Undefined Method active_connection? for nil:NilClass HOT 12
- crash after fork with 2.4.0 HOT 1
- Connection resets and connection timeouts on threads after fork
- Push tag v2.4.1 HOT 1
- 2.4.1 Memory leak? HOT 2
- After fork hook should (possibly) run in parent process too HOT 7
- Issue on setup ConnectionPool using RedisCluster HOT 1
- undefined method `set' for an instance of ConnectionPool HOT 4
- The reap PR added methods but didn't bump the version
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from connection_pool.