forked from kenzuya/unshackle
refactor(api): end every remote session through SessionStore._retire and close the store at shutdown
This commit is contained in:
@@ -953,7 +953,7 @@ Report the install status of the external binaries unshackle depends on (the sam
|
||||
!!! note "Developer feature"
|
||||
The `/api/session/*` endpoints power unshackle's **remote download** mode. A thin local client authenticates once against a remote server, then fetches titles, tracks, and segments, and proxies DRM licensing back through it. The server mounts these endpoints in `--remote-only` mode, and they are what the built-in `RemoteService` client drives. Most end users never call them directly.
|
||||
|
||||
The server holds remote sessions in memory. They expire after `serve.session_ttl` (default 300s) without a request, except while awaiting interactive authentication input, which uses a 600s window. A remote session binds to the IP that made it, so the server rejects a request from a different IP with `403 FORBIDDEN`.
|
||||
The server holds remote sessions in memory. They expire after `serve.session_ttl` (default 300s) without a request, except while the login runs, which can stay idle for the larger of `session_ttl` and 600s. A remote session binds to the IP that made it, so the server rejects a request from a different IP with `403 FORBIDDEN`.
|
||||
|
||||
### Remote session lifecycle overview
|
||||
|
||||
|
||||
@@ -384,14 +384,13 @@ generally never touch this directly, but it explains behaviour you might observe
|
||||
|---|---|---|
|
||||
| Idle session TTL | **300s** (5 min) default | Refreshed on every request to the session and when a `titles` or `tracks` request ends. A remote session does not expire while a request works on it or while its remote session channel is open |
|
||||
| Max concurrent sessions | **100** default | When full, the least recently used remote session of the API key that holds the most is evicted. A remote session that a request works on goes last |
|
||||
| Auth/input timeout | **600s** (10 min) | Sessions still authenticating or awaiting a prompt use this longer window instead of the TTL |
|
||||
| Auth/input timeout | **600s** (10 min) | A remote session that still logs in, a prompt included, can stay idle for the larger of the TTL and this value |
|
||||
| Cleanup sweep | every 60s | Expired sessions are removed and their input prompts cancelled |
|
||||
|
||||
!!! note "Auth is never rushed"
|
||||
A remote session that is still `authenticating` or waiting on `pending_input` is
|
||||
**not** subject to the short 300s TTL. It gets the full 600s auth window. This gives
|
||||
you time to enter an interactive code without the remote session vanishing
|
||||
mid-prompt.
|
||||
A remote session that is still `authenticating` or waiting on `pending_input` can stay
|
||||
idle for the larger of `session_ttl` and 600s. This gives you time to enter an interactive
|
||||
code without the remote session vanishing mid-prompt.
|
||||
|
||||
The TTL and max-session limits are read from server config:
|
||||
|
||||
@@ -540,8 +539,8 @@ layer.
|
||||
channel carries it, or the client polls while its own requests run. A call that no client fetches within 10 seconds
|
||||
fails then, because no client is listening. A fetched call waits 60 seconds for its answer.
|
||||
The call leaves the auth status as it was. An answer never marks the remote session as client-authenticated.
|
||||
- `AUTH_INPUT_TIMEOUT = 600.0` seconds. This is also the TTL granted to
|
||||
`AUTHENTICATING` sessions in the store. A remote session that waits on a prompt stays `AUTHENTICATING`.
|
||||
- `AUTH_INPUT_TIMEOUT = 600.0` seconds. An `AUTHENTICATING` remote session expires in the store after
|
||||
the larger of `session_ttl` and this value. A remote session that waits on a prompt stays `AUTHENTICATING`.
|
||||
|
||||
`GET /api/session/{id}/prompt` returns one of:
|
||||
|
||||
@@ -610,16 +609,20 @@ Source: `unshackle/core/api/session_store.py`. A singleton you get from
|
||||
take effect without recreating the store.
|
||||
- **`create()`** evicts the least-recently-accessed remote session of the API key that holds the most when at capacity,
|
||||
then stores a complete `SessionEntry` from the fields of the `create` handler and publishes the `create` event.
|
||||
- **`get()`** refreshes `last_accessed` through `touch()`. It returns `None` (and
|
||||
deletes the entry) if an authenticated remote session has been idle longer than the
|
||||
TTL. Remote sessions in `AUTHENTICATING` are exempt from TTL expiry.
|
||||
- **`cleanup_expired()`** runs every 60s: authenticated remote sessions expire at
|
||||
`ttl`, in-flight-auth remote sessions expire at `AUTH_INPUT_TIMEOUT`. The removal of
|
||||
a remote session cancels its `InputBridge` and deletes its cache directory (pruning
|
||||
empty parent dirs up to, but not including, the cache root).
|
||||
- The server calls **`cancel_all_bridges()`** on shutdown. It ends each open remote session, which
|
||||
unblocks any waiting auth threads, and deletes the cache directory of each one. The server then waits up
|
||||
to 5 seconds for each login that still runs, and deletes its cache directory again when it ends.
|
||||
- **Expiry.** `get()` and `cleanup_expired()` use one rule. A remote session that no request holds
|
||||
expires when it is idle for longer than `ttl`. While its login runs (`AUTHENTICATING`), the limit is
|
||||
the larger of `ttl` and `AUTH_INPUT_TIMEOUT`.
|
||||
- **`get()`** refreshes `last_accessed` through `touch()`. It returns `None` and
|
||||
deletes the entry when the remote session has expired.
|
||||
- **`cleanup_expired()`** runs every 60s and removes each expired remote session.
|
||||
- **Removal.** Eviction, expiry and `delete()` end the remote session the same way: they cancel its
|
||||
`InputBridge`, close its channel, send the `delete` dashboard event, schedule a staged service reload
|
||||
and delete its cache directory (pruning empty parent dirs up to, but not including, the cache root).
|
||||
- **`track_login(task)`** keeps each login task of `session/create` until it ends.
|
||||
- The server calls **`close()`** on shutdown. It ends each open remote session, which
|
||||
unblocks any waiting auth threads, and deletes the cache directory of each one. It sends no dashboard event
|
||||
and schedules no reload. It then waits up to 5 seconds for each login that still runs, and stops the sweep.
|
||||
A login that ends after the shutdown deletes its cache directory again.
|
||||
|
||||
`SessionEntry` fields:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user