The connection pool owns the connections.
The session:
Borrows a connection from the pool
Uses it
Returns it back to the pool when done
The session itself is just a unit-of-work + identity map .
When the with block exits:
The session is closed
Any checked-out connection is returned to the pool
SQLAlchemy does NOT blindly trust the connection
The pool decides whether to:
keep it
or discard it
So yes — the connection is returned in all cases, but whether it is reused or dropped depends on its health.