Skip to content

[v3-2-test] Ensure that DB migrations run in a single connection. (#65231)#65368

Merged
ashb merged 1 commit intov3-2-testfrom
backport-f8e0876-v3-2-test
Apr 16, 2026
Merged

[v3-2-test] Ensure that DB migrations run in a single connection. (#65231)#65368
ashb merged 1 commit intov3-2-testfrom
backport-f8e0876-v3-2-test

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot commented Apr 16, 2026

This was discovered by running with a custom External DB manager that had some
gnarly queries that ended up being locked behind this transaction.

_single_connection_pool replaces settings.engine with a
SingletonThreadPool engine. But work_session was created before that — it
still holds an internal reference to the old engine object.
_single_connection_pool has no way to rebind work_session.

So when _get_current_revision(session=work_session) runs on line 1203 — inside
the _single_connection_pool() block — it calls session.connection() which goes
through the old engine, not the SingletonThreadPool. The old engine's pool was
disposed and recreated empty by engine.dispose(), so it creates a brand new
connection. That connection is completely outside _single_connection_pool's
control.

_single_connection_pool guarantees one connection on the new engine. It can't
prevent work_session from creating connections on the old one. The name is a
bit of a lie — it's really "single connection pool for new code that uses
settings.engine", not "single connection total."
(cherry picked from commit e3fea3a)

Co-authored-by: Ash Berlin-Taylor ash@apache.org

…nection. (#65231)

This was discovered by running with a custom External DB manager that had some
gnarly queries that ended up being locked behind this transaction.

`_single_connection_pool` replaces `settings.engine` with a
SingletonThreadPool engine. But `work_session` was created before that — it
still holds an internal reference to the old engine object.
_single_connection_pool has no way to rebind work_session.

So when _get_current_revision(session=work_session) runs on line 1203 — inside
the _single_connection_pool() block — it calls session.connection() which goes
through the old engine, not the SingletonThreadPool. The old engine's pool was
disposed and recreated empty by engine.dispose(), so it creates a brand new
connection. That connection is completely outside _single_connection_pool's
control.

_single_connection_pool guarantees one connection on the new engine. It can't
prevent work_session from creating connections on the old one. The name is a
bit of a lie — it's really "single connection pool for new code that uses
settings.engine", not "single connection total."
(cherry picked from commit e3fea3a)
(cherry picked from commit f8e0876)

Co-authored-by: Ash Berlin-Taylor <ash@apache.org>
@ashb ashb marked this pull request as ready for review April 16, 2026 13:50
@ashb ashb changed the title [v3-2-test] [v3-2-test] Ensure that DB migrations run in a single connection. (#65231) [v3-2-test] Ensure that DB migrations run in a single connection. (#65231) Apr 16, 2026
@ashb ashb merged commit 7f92be8 into v3-2-test Apr 16, 2026
73 checks passed
@ashb ashb deleted the backport-f8e0876-v3-2-test branch April 16, 2026 16:10
vatsrahul1001 pushed a commit that referenced this pull request Apr 17, 2026
…nection. (#65231) (#65368)

This was discovered by running with a custom External DB manager that had some
gnarly queries that ended up being locked behind this transaction.

`_single_connection_pool` replaces `settings.engine` with a
SingletonThreadPool engine. But `work_session` was created before that — it
still holds an internal reference to the old engine object.
_single_connection_pool has no way to rebind work_session.

So when _get_current_revision(session=work_session) runs on line 1203 — inside
the _single_connection_pool() block — it calls session.connection() which goes
through the old engine, not the SingletonThreadPool. The old engine's pool was
disposed and recreated empty by engine.dispose(), so it creates a brand new
connection. That connection is completely outside _single_connection_pool's
control.

_single_connection_pool guarantees one connection on the new engine. It can't
prevent work_session from creating connections on the old one. The name is a
bit of a lie — it's really "single connection pool for new code that uses
settings.engine", not "single connection total."
(cherry picked from commit e3fea3a)
(cherry picked from commit f8e0876)

Co-authored-by: Ash Berlin-Taylor <ash@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant