Giter VIP home page Giter VIP logo

Comments (3)

mperham avatar mperham commented on August 26, 2024

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:

  1. 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.
  2. RSpec checks out the shared_connection and promptly issues a ROLLBACK (which adversely affects the previous BEGIN)
  3. RSpec then checks the shared_connection back in.
  4. 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.

sarmiena avatar sarmiena commented on August 26, 2024

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.

djanowski avatar djanowski commented on August 26, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.