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

Abierto
#1,663 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
62/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
postgresql, rust
Área
backend, database

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.
Lenguaje dominante
Rust
Estrellas
1
Forks
193
Merge medio
23 h 37 min
PR fusionados (30 d)
1

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de DogStark/PetChain-Contracts

Todos los issues de DogStark/PetChain-Contracts

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.