Files
aptly/task
André Roth 4f339be879 fix(task): Eliminate data race in RunTaskInBackground return value
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
2026-05-26 00:29:46 +02:00
..
2022-01-27 09:30:14 +01:00