Skip to content

Concurrent cron Add calls can allocate the same job ID #678

Closed

Description

@PierrunoYT

Summary

Cron job creation allocates an ID with a check-then-create sequence. Two processes adding jobs in the same second can both observe the same directory as absent, select the same ID, and write into the same job directory.

Relevant code

  • internal/cron/store.go: Add calls allocID and later writeJob.
  • allocID uses os.Stat to find an available timestamp ID.
  • writeJob uses os.MkdirAll, which does not reserve the ID exclusively.
  • Both writers use metadata.json.tmp.

Observed at commit 6fc1220.

Failure modes

One job can replace another, writers can interfere through the shared temp name, or both callers can receive the same ID.

Suggested fix

Reserve candidates atomically with os.Mkdir(dir, 0700), retry only on os.ErrExist, and remove the reserved directory if initial metadata creation fails. Add a concurrent cross-store test with a frozen clock.

Activity

  1. added
    issue-approved
    on Jul 21, 2026
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

    issue-approved

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions