Tolerate read-only database in API and content worker heartbeats - #7914
Open
lucasc017 wants to merge 1 commit into
Open
Tolerate read-only database in API and content worker heartbeats#7914lucasc017 wants to merge 1 commit into
lucasc017 wants to merge 1 commit into
Conversation
During zero-downtime deployments the database may temporarily switch to read-only mode. The heartbeat mechanism treated all write failures as fatal, causing API and content pods to crash-loop even though they could still serve read traffic (collection downloads, EE pulls, API GETs). Detect PostgreSQL SQLSTATE 25006 (ReadOnlySqlTransaction) and skip the heartbeat write instead of killing the worker. When the database becomes writable again, normal heartbeat behaviour resumes automatically. Fixes: AAP-80698 AI-ASSISTED-BY: Claude Opus 4.6 (1M context) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Member
|
From an earlier discussion on chat: "The heartbeat is only successful if the timestamp in the database was updated, because other components will read that timestamps and draw conclusions from it." This approach is unsafe. Also there is consideration for zero downtime upgrades in a live database: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
25006) by skipping heartbeat writes instead of crash-looping_is_read_only_db_error()helper to detect read-only transaction errors across the psycopg__cause__chainContext
Galaxy.ansible.com's zero-downtime deployment temporarily switches the database to read-only. After pulpcore commit
3e8183bcc("Mark a failed heartbeat as a catastrophic failure"), heartbeat write failures became fatal — causing API and content pods to crash-loop during this window even though they could still serve read requests.Three crash sites are fixed in each of the two affected entrypoints (
pulpcore/app/entrypoint.pyandpulpcore/content/__init__.py):AppStatus.objects.create()INSERT fails → setapp_status = None, retry on next heartbeat cyclesave_heartbeat()UPDATE fails → log warning, skip this cycleapp_status.delete()DELETE fails → log info, continue cleanupThe task worker (
pulpcore/tasking/worker.py) already handles heartbeat failures gracefully and is unaffected.Fixes: AAP-80698
Test plan
_is_read_only_db_error()helper (pgcode, sqlstate, no-cause, wrong-code, nested-cause)app_statusis None, recovery when DB becomes writable)run()cleanup (tolerates DB error on delete, skips when noapp_status)asave_heartbeatskip, read-onlyacreateskip)🤖 Generated with Claude Code