fix(sessions): nil map panic in updateSandboxSummary goroutine
CI / CI (pull_request) Successful in 2m24s

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
This commit is contained in:
Admin Bot
2026-09-29 16:10:43 +08:00
parent 1e17706367
commit da361f2a21
+10 -1
View File
@@ -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)