Skip to content

Make database heartbeat more robust#21734

Merged
mvdbeek merged 2 commits intogalaxyproject:devfrom
mvdbeek:make_database_heartbeat_survive_lost_database_connection
Feb 10, 2026
Merged

Make database heartbeat more robust#21734
mvdbeek merged 2 commits intogalaxyproject:devfrom
mvdbeek:make_database_heartbeat_survive_lost_database_connection

Conversation

@mvdbeek
Copy link
Copy Markdown
Member

@mvdbeek mvdbeek commented Feb 3, 2026

Should fix #21713

How to test the changes?

(Select all options that apply)

  • I've included appropriate automated tests.
  • This is a refactoring of components with existing test coverage.
  • Instructions for manual testing are as follows:
    1. [add testing steps and prerequisites here if you didn't write automated tests covering all your changes]

License

  • I agree to license these and all my past contributions to the core galaxy codebase under the MIT license.

@mvdbeek mvdbeek changed the title [25.]1 Make database heartbeat more robust [25.1] Make database heartbeat more robust Feb 3, 2026
@github-actions github-actions Bot added the area/database Galaxy's database or data access layer label Feb 3, 2026
@github-actions github-actions Bot added this to the 26.1 milestone Feb 3, 2026
@mvdbeek mvdbeek marked this pull request as draft February 3, 2026 20:04
Only check session.connection().invalidated when there's an existing
transaction. This avoids checking out a new connection from the pool
that would never be returned, causing "too many clients" errors during
integration tests.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Comment thread lib/galaxy/model/base.py
session = session()
trans = session.get_transaction()
if (trans and not trans.is_active) or session.connection().invalidated:
if trans and (not trans.is_active or session.connection().invalidated):
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jdavcs can you sanity check this ? the integration tests were causing postgres to run out of connections prior to this change, supposedly because session.connection() checking out a connection and then never close it, so now we only check if there's an existing transaction.

@mvdbeek mvdbeek marked this pull request as ready for review February 4, 2026 08:17
@jdavcs jdavcs self-requested a review February 9, 2026 14:26
Comment thread lib/galaxy/model/base.py
session = session()
trans = session.get_transaction()
if (trans and not trans.is_active) or session.connection().invalidated:
if trans and (not trans.is_active or session.connection().invalidated):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this affects anything: if condition satisifes, we only do session.rollback(), and accoriding to the docs, if no transaction is in progress, this method is a pass-through.(ref + ref). So in the current version (before this change), it would either rollback an existing transaction or do nothing, after the change it will do exactly the same thing.

I didn't find any mention of a connection-related side effect in case of a noop rollback, but I didn't dig too deep. That said, the edit doesn't do any harm, so if you think it's worth a try, that's fine.

Copy link
Copy Markdown
Member Author

@mvdbeek mvdbeek Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this what happens:

if session.connection().invalidated and invalidated is False we don't enter the branch but we have created a new connection that never gets cleaned up ?

Why else would this fix the integration tests ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also see the commit message for a different phrasing in case that's not clear ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooooh! You are right! We create a connection in the if condition test - in order to test whether it's invalidated! Because, as per docs, "Either the Connection corresponding to the current transaction is returned, or if no transaction is in progress, a new one is begun and the Connection returned". Yikes. This was subtle. And pretty terrible. Thanks!

Copy link
Copy Markdown
Member

@jdavcs jdavcs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks fine (see inline comment)

@mvdbeek mvdbeek merged commit 35d8e9a into galaxyproject:dev Feb 10, 2026
54 of 59 checks passed
@github-actions
Copy link
Copy Markdown

This PR was merged without a "kind/" label, please correct.

@nsoranzo nsoranzo deleted the make_database_heartbeat_survive_lost_database_connection branch February 10, 2026 15:33
@mvdbeek mvdbeek changed the title [25.1] Make database heartbeat more robust Make database heartbeat more robust Feb 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/database Galaxy's database or data access layer kind/bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Kombu error

4 participants