From db6998fc78e998391523079b6c1f3b071b353d44 Mon Sep 17 00:00:00 2001 From: mesutoezdil Date: Sat, 25 Jul 2026 12:08:01 +0200 Subject: [PATCH] fix: cleanup uses fresh context after volume create failure if the failure was a ctx deadline or cancel, cleanup used the same ctx and failed for the same reason, leaking the volume. give it a fresh 30s timeout instead. --- cmd/ateapi/internal/controlapi/volumes.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/ateapi/internal/controlapi/volumes.go b/cmd/ateapi/internal/controlapi/volumes.go index 161c74e8c..65a5b5987 100644 --- a/cmd/ateapi/internal/controlapi/volumes.go +++ b/cmd/ateapi/internal/controlapi/volumes.go @@ -19,6 +19,7 @@ import ( "errors" "fmt" "log/slog" + "time" "github.com/agent-substrate/substrate/cmd/ateapi/internal/store" "github.com/agent-substrate/substrate/internal/volume" @@ -52,7 +53,10 @@ func (s *Service) createActorVolumes(ctx context.Context, ref *ateapipb.ObjectRe storageVolumeID, err := getVolumePlugin().CreateVolume(ctx, uniqueVolName, vol.ExternalVolumeTemplate.Capacity.String(), vol.ExternalVolumeTemplate.StorageClassName) if err != nil { // TODO: need better system - best effort cleanup of already created volumes - _ = s.deleteActorVolumes(ctx, ref, volumes) + // use a fresh timeout so cleanup still runs if ctx is why CreateVolume failed + cleanupCtx, cancel := context.WithTimeout(context.WithoutCancel(ctx), 30*time.Second) + _ = s.deleteActorVolumes(cleanupCtx, ref, volumes) + cancel() return nil, status.Errorf(codes.Internal, "failed to create volume %q: %v", vol.Name, err) } volumes = append(volumes, &ateapipb.ExternalVolume{