Lock around connection state changes in connection pool
We ought to place locking around the state changes in the connection pool.
We don't actually need these for the async cases, since the implementations are organised so that no async/await is used within the state changes, but we'll want it for the threaded case, to ensure thread safety.
Rather than add extra backend code, we could instead opt to do this in an implementation that only locks in the threaded case, something like...
class ThreadLock: def __init__(self): self.lock = threading.Lock() def __enter__(...): self.lock.acquire() def __exit__(...): self.lock.release() def __aenter__(...): pass def __aexit__(...): pass
The async with self.thread_lock: blocks would in any case be good visual indicators that no async/await code should be used within the block.