tenseleyflow/shithub / b8dabf2

Browse files

api/actions_lifecycle_rest: detach cleanup goroutine via WithoutCancel

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
b8dabf24fdba0c77ae755af45136e55bfc39fc1e
Parents
c6a11de
Tree
0587b1a

1 changed file

StatusFile+-
M internal/web/handlers/api/actions_lifecycle_rest.go 8 4
internal/web/handlers/api/actions_lifecycle_rest.gomodified
@@ -119,7 +119,7 @@ func (h *Handlers) actionsRunDelete(w http.ResponseWriter, r *http.Request) {
119119
 		return
120120
 	}
121121
 	if h.d.ObjectStore != nil && len(objectKeys) > 0 {
122
-		go h.purgeArtifactObjects(objectKeys)
122
+		go h.purgeArtifactObjects(context.WithoutCancel(r.Context()), objectKeys)
123123
 	}
124124
 	w.WriteHeader(http.StatusNoContent)
125125
 }
@@ -128,8 +128,12 @@ func (h *Handlers) actionsRunDelete(w http.ResponseWriter, r *http.Request) {
128128
 // request lifecycle. Failures are logged but never surfaced — the
129129
 // authoritative DB row is gone, and the cleanup sweeper retries
130130
 // orphan-object deletion on its own schedule.
131
-func (h *Handlers) purgeArtifactObjects(keys []string) {
132
-	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
131
+//
132
+// parent is expected to be `context.WithoutCancel(r.Context())` so
133
+// the goroutine survives response completion while still carrying
134
+// trace/log values from the originating request.
135
+func (h *Handlers) purgeArtifactObjects(parent context.Context, keys []string) {
136
+	ctx, cancel := context.WithTimeout(parent, 30*time.Second)
133137
 	defer cancel()
134138
 	for _, k := range keys {
135139
 		if err := h.d.ObjectStore.Delete(ctx, k); err != nil {
@@ -247,7 +251,7 @@ func (h *Handlers) actionsArtifactDelete(w http.ResponseWriter, r *http.Request)
247251
 		return
248252
 	}
249253
 	if h.d.ObjectStore != nil {
250
-		go h.purgeArtifactObjects([]string{artifact.ObjectKey})
254
+		go h.purgeArtifactObjects(context.WithoutCancel(r.Context()), []string{artifact.ObjectKey})
251255
 	}
252256
 	w.WriteHeader(http.StatusNoContent)
253257
 }