Skip to main content

Module session

Module session 

Source
Expand description

Bounded session pools for concurrent, per-query-context Snowflake access.

On the v1 query endpoint, statement context (warehouse/role/database/ schema) is session-global — changed via USE and shared by every query on the session token. So a query that needs a specific context must hold its session exclusively for the USE … + query. To get concurrency and per-query context without re-authenticating per query, each (account, user) keeps a bounded pool of up to max authenticated sessions (each a separate browser auth): a query checks one out, applies any USE needed (skipping USEs already in effect), runs, and returns it.

  • Concurrency is capped at max by a tokio::sync::Semaphore: a permit is held for the whole checkout, and a new session is created only while holding a permit with no idle session available — so the live-session count (and thus the number of browser auths) never exceeds max, and grows lazily with demand.
  • Every member is tracked in one slot table (a std::sync::Mutex never held across an .await): an idle slot parks its session handle; a checked-out slot’s handle lives in the Checkout. Both states stay visible to the (sync) menu/status snapshots, which is how each individual auth is listed.
  • Session creation (browser SSO) is serialized across all pools by a shared auth gate (held by the engine’s create closure) so only one auth window opens at a time.

Structs§

Checkout
A session checked out of a pool.
MemberInfo
A serializable snapshot of one pool member (one authenticated session).
PoolRegistry
The account-agnostic registry of session pools, keyed by (account, user).
QueryContext
A concrete statement context (resolved warehouse/role/database/schema names).
RunningQuery
The query a member is currently running (set while checked out).
SessionInfo
A serializable snapshot of one pool, used for sessions/status/menu.
SessionKey
Identifies a pool by its (account, user) — one authentication identity.
SessionPool
A bounded pool of authenticated sessions for one (account, user).