mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-05-30 04:20:53 +00:00
4f339be879
RunTaskInBackground() previously returned *task AFTER releasing list.Lock()
and sending the task to the consumer queue. This created a data race:
1. list.queue <- task (consumer receives)
2. Consumer: list.Lock() → task.State = RUNNING → list.Unlock()
3. RunTaskInBackground: return *task (struct copy WITHOUT lock)
Steps 2 and 3 can execute concurrently — consumer writes task.State
while RunTaskInBackground reads the entire struct via copy.
Fix: Copy the task struct BEFORE unlocking, while list.Lock() is still
held. At this point the task was just created and no other goroutine can
access it, so the copy is guaranteed consistent (always State=IDLE).
The returned copy is a snapshot of the initial task state, which is what
callers expect — the task ID and name for tracking purposes.
Safety invariant maintained:
- I4: All struct copies happen while list.Lock() is held
Changes:
- task/list.go: RunTaskInBackground() copies *task before unlock,
returns the pre-made copy instead of dereferencing after unlock