Skip to content

Campaign can stay in sending forever if jobs settle before the broadcast link is written #124

Open

Description

@JuansesDev

What happens

ExecuteCampaign enqueues the recipient jobs and only afterwards links the campaign to the broadcast. The cascade that writes final counts back to the campaign requires campaigns.broadcast_id to match and campaigns.status = 'sending'. If every job settles inside the window between enqueue and link, the cascade never matches and nothing else reconciles campaign rows, so the campaign stays sending permanently.

Reported as suspected: the window is small and has not been reproduced.

Where

  • backend/internal/service/worker.go:75-106 — enqueue then link.
  • backend/internal/db/campaigns.sql.go:259-268 — the cascade predicate.
  • backend/internal/db/broadcasts.sql.go:209-219 — reconciliation covers broadcasts only.

Impact

A campaign with no progress and no terminal state.

Proposed fix

Create the broadcast id first and set campaigns.broadcast_id in the same transaction as the enqueue.

Acceptance

  • A test that forces jobs to settle immediately does not leave the campaign in sending.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions