]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
mutex asyncpg / aiomysql connection state changes
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 23 Feb 2021 02:49:09 +0000 (21:49 -0500)
committermike bayer <mike_mp@zzzcomputing.com>
Thu, 25 Feb 2021 20:49:52 +0000 (20:49 +0000)
commita5b76f7b07e620ece882137ceb51bace3898fad5
tree03aac63d2e9af851a317503e577e6bea2ff35793
parentdc615763d39916e9c037c7c376db1817cdf02764
mutex asyncpg / aiomysql connection state changes

Added an ``asyncio.Lock()`` within SQLAlchemy's emulated DBAPI cursor,
local to the connection, for the asyncpg dialect, so that the space between
the call to ``prepare()`` and ``fetch()`` is prevented from allowing
concurrent executions on the connection from causing interface error
exceptions, as well as preventing race conditions when starting a new
transaction. Other PostgreSQL DBAPIs are threadsafe at the connection level
so this intends to provide a similar behavior, outside the realm of server
side cursors.

Apply the same idea to the aiomysql dialect which also would
otherwise be subject to corruption if the connection were used
concurrently.

While this is an issue which can also occur with the threaded
connection libraries, we anticipate asyncio users are more likely
to attempt using the same connection in multiple awaitables
at a time, even though this won't achieve concurrency for that
use case, as the asyncio programming style is very encouraging
of this.  As the failure modes are also more complicated under
asyncio, we'd rather not have this being reported.

Fixes: #5967
Change-Id: I3670ba0c8f0b593c587c5aa7c6c61f9e8c5eb93a
doc/build/changelog/unreleased_14/5967.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/mysql/aiomysql.py
lib/sqlalchemy/dialects/postgresql/asyncpg.py