!PooledConnection could end up being garbage collected in an other thread than the one which created it.
- this triggered an assertion (#3504)
- even if the assertion was avoided by properly tracking the !PooledConnection, with some backends (pysqlite) it's illegal to manipulate a Connection from a different thread than the one which created the instance.
Therefore we had to ensure that upon thread termination, the connection created and used by the thread was properly closed.
Closes #3504.