Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix checking cancelled connections back into the connection pool #1095

Commits on May 12, 2020

  1. Fix checking cancelled connections back into the connection pool

    If
        * BeginTx is called with a non-default isolation level,
        * The context is canceled before SET TRANSACTION ISOLATION LEVEL
        completes,
    then the connection:
        * has the cancelled property set to "context cancelled",
        * has the closed property set to true,
    and,
        * BeginTx returns "context canceled"
    
    Because of this, the connection gets put back into the connection pool.
    When it is checked out again, if BeginTx is called on it again _without_
    an isolation level,
        * then we fall into the mc.closed.IsSet() check in begin(),
        * so we return ErrBadConn,
        * so the driver kicks the broken connection out of the pool
        * (and transparently retries to get a new connection that isn't
        broken too).
    
    However, if BeginTx is called on the connection _with_ an isolation
    level, then we return a context canceled error from the SET TRANSACTION
    ISOLATION LEVEL call.
    
    That means the broken connection will stick around in the pool forever
    (or until it's checked out for some other operation that correctly
    returns ErrBadConn).
    
    The fix is to check for the connection being closed before executing SET
    TRANSACTION ISOLATION LEVEL.
    KJTsanaktsidis committed May 12, 2020
    Copy the full SHA
    cd56c6f View commit details
    Browse the repository at this point in the history
  2. Copy the full SHA
    978b6bd View commit details
    Browse the repository at this point in the history