[backend-2fa] Migration lock (`migration_lock.rs`) does not release advisory lock on panic — subsequent deployments deadlock

未关闭
#1,663 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
62/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
postgresql, rust
领域
backend, database

调研方向

Start in backend-2fa/src/migration_lock.rs: trace where the advisory lock is acquired (pg_try_advisory_lock) and where the Drop cleanup runs. Decide between transaction-scoped locking and a lock timeout, then document the choice in comments. Add a test that forces a mid-migration failure and verifies the lock is no longer held; done means the lock is released after the simulated crash and the strategy is documented.

由索引模型根据 Issue 内容生成。

描述

bug infrastructure priority: high Rust

Problem

backend-2fa/src/migration_lock.rs acquires a Postgres advisory lock before running schema migrations to prevent concurrent migration runs. If the migration process panics (e.g. due to a database error mid-migration), the advisory lock may not be released because the cleanup code runs in a Drop impl.

However, if the process is killed with SIGKILL (OOM killer, container restart), Drop does not run. Postgres advisory locks acquired with pg_try_advisory_lock are session-scoped and release when the session closes. But if the connection is kept alive (e.g. by a connection pool that recycles connections), the lock may persist across process restarts within the same connection lifetime.

Suggested Fix

  1. Use pg_advisory_xact_lock (transaction-scoped) instead of pg_try_advisory_lock (session-scoped) for the migration lock. Transaction-scoped locks are released automatically when the transaction commits or rolls back, even on panic or SIGKILL.
  2. Alternatively, add a lock timeout (SET lock_timeout = '30s') before acquiring the session lock.
  3. Document the chosen lock strategy in migration_lock.rs comments.
  4. Add a test that simulates a mid-migration failure and asserts the lock is released.

Acceptance Criteria

  • Advisory lock is reliably released even on process crash.
  • Lock strategy is documented in source.
  • Test covers lock release after simulated failure.
主要语言
Rust
星标
1
派生
193
平均合并
23 小时 37 分钟
30 天内合并 PR
1

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

DogStark/PetChain-Contracts 的其他 Issue

查看 DogStark/PetChain-Contracts 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。