Skip to content

Fix AWS Batch completion panic after job recovery - #137

Open
sclaw wants to merge 4 commits into
mainfrom
bugfix/negative-wg-counter
Open

sclaw wants to merge 4 commits into
mainfrom
bugfix/negative-wg-counter

Conversation

@sclaw

@sclaw sclaw commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator

Closes #136.

Context

SEPEX submits AWS Batch jobs, then keeps each active job in memory while status updates arrive. When a job reaches a terminal status, the status handler closes it and calls RunFinished() to release its completion waiter. On API restart, recovery rebuilds active AWS Batch jobs from database records and checks their current AWS status.

What went wrong

New AWS Batch jobs increment wgRun during Create(), but recovered jobs did not increment it before becoming active. The first terminal update for a recovered job called RunFinished(), which decremented a zero-valued WaitGroup and crashed the API with sync: negative WaitGroup counter. Repeated restarts could reattach the same unfinished jobs and trigger the crash again.

Overlapping completion paths could also attempt cleanup more than once. A status update, recovery, and a dismissal can all lead to job closure.

Changes

  • Initialize wgRun before adding a recovered AWS Batch job to the active-job map.
  • Complete recovered jobs that are already terminal when recovery checks AWS.
  • Make RunFinished() and Close() run once per AWS Batch job, so overlapping completion paths cannot decrement the counter or send cleanup twice.
  • Complete the waiter after dismissal cleanup, consistent with terminal status handling.
  • Add a regression test that calls RunFinished() concurrently for multiple jobs and verifies each waiter unblocks.

Verification

From api/: go test -race ./jobs -count=1 passed.

Live AWS Batch load and restart behavior was not tested; that still needs deployment-level verification.

sclaw added 3 commits October 15, 2026 09:13
gh: Panic: `sync: negative WaitGroup counter` in `AWSBatchJob.RunFinished` under high concurrent job load
Fixes #136
@sclaw
sclaw force-pushed the bugfix/negative-wg-counter branch from 52f09ed to e56c1d0 Compare October 15, 2026 14:31
@sclaw
sclaw requested a review from ar-siddiqui October 15, 2026 14:31
…ttempt to avoid pull quota limits. Also run docker build in foreground so pyecho:latest is available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Panic: sync: negative WaitGroup counter in AWSBatchJob.RunFinished under high concurrent job load

1 participant