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.
This commit is contained in:
Julian Sommer
2026-08-26 11:33:51 +10:00
parent 78a0dc7661
commit e3d394864d
+5 -1
View File
@@ -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 {