Possible Connection Leak?

Issue #3527 closed
Tim Mitchell created an issue

SQLA 1.0.8 I am trying to debug an inexplicable 'connection unexpectedly closed' error when I run a test suite (with lots of engine.dispose()s). When I came across this.

Given a pretty normal query in a ThreadLocal session and a QueuePool

with db_context() as session:
        session.query(tables.Attachment).get(attachment_id)

When I look at the callstack for a new connection I see this:

...
Query._connection_from_session(..., close_with_result=True)
Session._connection_for_bind(..., kw={close_with_result=True))
SessionTransaction._connection_for_bind(...)  # close_with_result NOT passed
Engine.contextual_connect(..., close_with_result=False)
...
# Create DBAPI connection

Specifying a NullPool makes everything work fine.

Comments (1)

  1. Mike Bayer repo owner

    hi there -

    to illustrate a bug you need to provide a short self contained test case. A good article that talks about this is here.

    As for the _connection_for_bind() methods, the "close_with_result" flag applies to the Engine.contextual_connect() method when the session is used in autocommit mode, which is not the case here. There's no bug illustrated in the Session here.

  2. Log in to comment