Skip to content

Migration lock acquisition error #484

@obazoud

Description

@obazoud

Describe the bug
Currently, when all three services (API, Delivery, Log) restart at the same time, there is a rare case where all of them attempt to run the migration concurrently. This leads to a migration lock acquisition error for the other services, causing them to fail to start.

migrate.New: failed to open database: try lock failed in line 0: SELECT pg_advisory_lock($1) (details: pq: unnamed prepared statement does not exist)

To Reproduce
Steps to reproduce the behavior:

  1. Redeploy all three services (API, Delivery, Log) simultaneously
  2. Observe the startup logs for each service
  3. Occasionally, only one service successfully acquires the migration lock and completes the migration; the other services fail to start due to a migration lock acquisition error

Expected behavior
If a service cannot acquire the migration lock, it should retry after a delay
Optionally, it should be possible to configure only one service to perform the migration, while others skip this step. Or enforce only API to perform this migration task.

Screenshots
N/A

Additional context
The migration lock is managed by the golang-migrate library here

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    Status

    Todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions