MCPcopy Create free account
hub / github.com/PostHog/duckgres / DestroySessionsForUser

Method DestroySessionsForUser

controlplane/session_mgr.go:758–782  ·  view source on GitHub ↗

DestroySessionsForUser tears down every active session owned by username (the per-user kill switch). Each DestroySession cancels the session's in-flight query (via the executor) and destroys the worker-side session; here we additionally force-close the client TCP connection so the client is dropped

(username string)

Source from the content-addressed store, hash-verified

756// per-user kill switch). Each DestroySession cancels the session's in-flight
757// query (via the executor) and destroys the worker-side session; here we
758// additionally force-close the client TCP connection so the client is dropped
759// immediately rather than lingering until its next query returns ErrWorkerDead
760// (mirrors OnWorkerCrash). Returns the number of sessions destroyed.
761//
762// Unlike DestroyAllSessions this does NOT close the manager lifecycle: the org
763// stays open for other users, and (unless the user is also disabled) for the
764// killed user's subsequent reconnects.
765func (sm *SessionManager) DestroySessionsForUser(username string) int {
766 type target struct {
767 pid int32
768 closer io.Closer
769 }
770 sm.mu.Lock()
771 var targets []target
772 for pid, s := range sm.sessions {
773 if s.Username == username {
774 targets = append(targets, target{pid: pid, closer: s.connCloser})
775 }
776 }
777 sm.mu.Unlock()
778
779 for _, t := range targets {
780 sm.DestroySession(t.pid)
781 // Drop the client connection immediately. The deferred close in
782 // handleConnection will also Close() this conn; a double close on a
783 // socket is harmless (the error is discarded).
784 if t.closer != nil {
785 _ = t.closer.Close()

Callers 2

KillUserSessionsMethod · 0.80

Calls 2

DestroySessionMethod · 0.95
CloseMethod · 0.65

Tested by 1