From e3d394864d5de4fff0d51bd822eac37ad302bf9c Mon Sep 17 00:00:00 2001 From: Julian Sommer <115516918+juliansommer@users.noreply.github.com> Date: Wed, 26 Aug 2026 11:33:51 +1000 Subject: [PATCH] fix: propagate KV read errors when releasing an ECS reservation releaseReservation returned nil for every kv.Get error, so a NATS timeout or connection drop was reported as a successful release and the stopped task's CPU/memory/GPU capacity leaked on that instance. Narrow the nil return to jetstream.ErrKeyNotFound, matching the pattern already used in service.go and task_stop.go, and return anything else. --- spinifex/handlers/ecs/instances.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spinifex/handlers/ecs/instances.go b/spinifex/handlers/ecs/instances.go index 533fdf1eb..e2d6970a5 100644 --- a/spinifex/handlers/ecs/instances.go +++ b/spinifex/handlers/ecs/instances.go @@ -3,6 +3,7 @@ package handlers_ecs import ( "context" "encoding/json" + "errors" "log/slog" "slices" "time" @@ -359,8 +360,11 @@ func (s *Service) recordDeploymentFailure(ctx context.Context, kv jetstream.KeyV func (s *Service) releaseReservation(ctx context.Context, kv jetstream.KeyValue, cluster, instanceID, taskID string, cpu, mem, gpu int) error { for range reservePlacementRetries { entry, err := kv.Get(ctx, InstanceKey(cluster, instanceID)) + if errors.Is(err, jetstream.ErrKeyNotFound) { + return nil + } if err != nil { - return nil //nolint:nilerr // instance gone; nothing to release + return err } var rec InstanceRecord if uerr := json.Unmarshal(entry.Value(), &rec); uerr != nil {