summaryrefslogtreecommitdiff
path: root/internal/askcli/command_delete.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-04 23:20:21 +0300
committerPaul Buetow <paul@buetow.org>2026-05-04 23:20:21 +0300
commit90feabaf14b67ef61124881164ef3636b1827398 (patch)
tree6503a4da2e0ea0cee0c3fd97e64de10dab0d6b38 /internal/askcli/command_delete.go
parent266bedf71fe8a54b86af038889522a68bae562a8 (diff)
askcli: serialize task alias cache writes to fix concurrent rename race
Two concurrent 'ask' invocations could race on the alias cache file: both wrote the JSON to a shared '<path>.tmp' filename and then both called os.Rename, so the loser failed with: replace task alias cache: rename .../task-aliases-v2.json.tmp .../task-aliases-v2.json: no such file or directory The shared tempfile also enabled lost updates because each process loaded the file independently before saving its own version on top. Fix: - Take an exclusive flock on a sentinel file (task-aliases-v2.json.lock) in the cache directory around the full load/modify/save cycle in both ensureTaskAliases and resolveTaskSelectorFromCache, using the existing internal/filelock package. - Switch save() to os.CreateTemp so each writer gets a unique tempfile name; the loser's tempfile is removed cleanly on rename failure. - Refactor resolveTaskSelectorFromCache by extracting finalizeResolvedTaskSelector to keep functions under 50 lines. Adds TestEnsureTaskAliases_ConcurrentCallsDoNotRaceOnTempFile, which reproduces the original error reliably on the unfixed code and now passes with -race. Amp-Thread-ID: https://ampcode.com/threads/T-019df49f-52a5-75b1-98d5-371a163ef100 Co-authored-by: Amp <amp@ampcode.com>
Diffstat (limited to 'internal/askcli/command_delete.go')
0 files changed, 0 insertions, 0 deletions