fix(kanban): wrap ALTER TABLE ADD COLUMN with race-safe helper - #21628
Closed
baocin wants to merge 1 commit into
Closed
fix(kanban): wrap ALTER TABLE ADD COLUMN with race-safe helper#21628baocin wants to merge 1 commit into
baocin wants to merge 1 commit into
Conversation
The kanban DB migration in _migrate_add_optional_columns reads a single PRAGMA table_info snapshot at entry, then issues multiple ALTER TABLE ADD COLUMN statements guarded by that snapshot. When two gateway processes restart concurrently (e.g. --replace takeover + cron job tick), the PRAGMA can be stale by the time a given ALTER TABLE executes, causing: sqlite3.OperationalError: duplicate column name: <name> Add _safe_add_column() which tries the ALTER TABLE and silently ignores 'duplicate column name' — another process already did it. Wraps every ADD COLUMN call in the migration so the pattern is safe regardless of which columns are added in the future.
Collaborator
Contributor
|
Closing as redundant — the same race-safe migration helper landed on We also followed it up with PR #22994 which removed the redundant double-init pattern in the gateway watchers ( Thanks for the clean writeup @baocin — the diagnosis was spot-on. References:
|
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.
The kanban DB migration in
_migrate_add_optional_columnsreads a singlePRAGMA table_info snapshot at entry, then issues multiple ALTER TABLE
ADD COLUMN statements guarded by that snapshot. When two gateway
processes restart concurrently (e.g.
--replacetakeover + cron jobtick), the PRAGMA can be stale by the time a given ALTER TABLE
executes, causing:
This has been hit in production on the
consecutive_failurescolumn.The same race will fire for any new column added to the migration in
the future.
Add
_safe_add_column()which tries the ALTER TABLE and silentlyignores
duplicate column name— another process already added it.Changes:
_safe_add_column(conn, table, col_def)withtry/except for OperationalError, only re-raising non-duplicate errors.
_migrate_add_optional_columnsnow go through
_safe_add_column.task_events.run_idALTER TABLE also uses the helper.