fix(project_events): use process-lifetime ctx for async SSE publish #8
Reference in New Issue
Block a user
Delete Branch "fix/sse-detach-ctx"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Follow-up to #7.
Bug
SSE board events never reached browsers. Root cause: the fire-and-forget publish goroutine inherited the HTTP request's context via
context.WithoutCancel(ctx). That context carries a request-scoped DB session that is returned to the pool the moment the handler completes. By the time the goroutine ranGetProjectByID+ per-uid access checks, the session was gone, soconnectedUIDsWithProjectAccesserrored out and returned an empty recipient set — every event silently dropped (uids=[] connected=[N]). The error only logged at Debug level, so it was invisible at the default Info level.Fix
detach()now returnsgraceful.GetManager().ShutdownContext()— a process-lifetime context backed by the global engine, cancelled on app shutdown so goroutines don't leak past teardown. The session tag is already resolved synchronously before the goroutine starts, so no request-scoped values are needed in the goroutine.Verification
Deployed to git.oleks.space and confirmed live: triggering a card move now logs
uids=[2] connected=[2]and the card relocates in a second browser tab with no refresh. All 15services/project_eventsunit tests pass;go build,go vetclean.One-line diff in spirit:
context.WithoutCancel(ctx)→graceful.GetManager().ShutdownContext()(plus import + doc comment).