From da361f2a212f2e707d6b377ae750925ae06bea2b Mon Sep 17 00:00:00 2001 From: Admin Bot Date: Tue, 29 Sep 2026 11:28:43 +0800 Subject: [PATCH] fix(sessions): nil map panic in updateSandboxSummary goroutine r.Context() is cancelled when HTTP handler returns; fetchEntitySummary returns nil on cancelled context. Two fixes: 1. Detached request with context.Background() for the goroutine call 2. Nil guard on current before map assignment --- internal/sessions/handler.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/internal/sessions/handler.go b/internal/sessions/handler.go index 3cfe99a..b6f9138 100644 --- a/internal/sessions/handler.go +++ b/internal/sessions/handler.go @@ -582,8 +582,17 @@ func (h *Handler) handleSandboxCreate(w http.ResponseWriter, r *http.Request, se } // updateSandboxSummary merges pod/svc metadata into the session memory_entity (fire-and-forget). +// Uses context.Background() because r.Context() is cancelled once the HTTP handler returns. func (h *Handler) updateSandboxSummary(r *http.Request, sessionID, podName, pvcName, svcDns string) { - current, _ := h.fetchEntitySummary(r, "session-"+sessionID, sessionID, "SESSION") + // Build a detached request carrying just the auth header. + detached, _ := http.NewRequestWithContext(context.Background(), r.Method, r.URL.String(), nil) + if auth := r.Header.Get("Authorization"); auth != "" { + detached.Header.Set("Authorization", auth) + } + current, _ := h.fetchEntitySummary(detached, "session-"+sessionID, sessionID, "SESSION") + if current == nil { + current = map[string]any{} + } current["pod_name"] = podName current["svc_dns"] = svcDns current["last_active_at"] = time.Now().UTC().Format(time.RFC3339)