mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-12-01 21:45:10 +00:00
fix(remote): end the remote logins and the pooled remote sessions of a relay when the server stops
This commit is contained in:
@@ -17,7 +17,7 @@ Start the server with [`unshackle serve`](../../guide/cli-reference.md). By defa
|
||||
- **CORS.** Every response carries permissive CORS headers, and the server answers `OPTIONS` preflight requests automatically.
|
||||
- **Compression.** JSON responses of 256 bytes or more are gzip-compressed when the client sends `Accept-Encoding: gzip`. A [slow response](#slow-responses) is not compressed.
|
||||
- **Service allowlist.** The effective allowlist for your API key filters the service-facing endpoints (the intersection of the global `serve.services` list and your per-key list). The server treats services you cannot use as unknown.
|
||||
- **Remote services.** A full-mode server can run a service through one of its own `remote_services` servers (see [Remote sessions](remote-sessions.md)). `GET /api/config` lists their names in `remote_services`, and `GET /api/services?remote=<name>` lists that server's services, each with `remote` set to the name. Add `"remote": "<name>"` to `POST /api/search`, `/api/list-titles`, `/api/list-tracks` or `/api/download`, and the server opens a remote session with its own key for that server: the remote logs in and resolves titles, tracks and licences, and a download still runs, decrypts and muxes here. The tag may be any case or an alias, and your allowlist applies to it. An unknown name is `400 INVALID_PARAMETERS`, a server that does not answer is `SERVICE_UNAVAILABLE`, and a tag it does not offer is `INVALID_SERVICE`. List calls from the same API key for the same title, profile, proxy, client region and service options share one remote session, which closes after 120 seconds unused. An optional `client_name` names your client on the remote server's dashboard as `serve (<client_name>)`. A relayed search opens no remote session. The server sends its own credentials, cookies and cache for the `profile` with the search. A service that searches with no login gets none of them. A `--remote-only` server does not relay. A remote login that waits on you (a pair code or URL to approve on another device) cannot answer through a list call, so poll `GET /api/remote/logins` alongside it: each entry carries the login's `notice`, its `qr` (the text of a QR code to scan, or null), and its `prompt` when it asks a question (an OTP), which you answer with `POST /api/remote/logins/{id}/input` and `{"response": "..."}`. A remote download job shows the same text as its own `notice`, and asks a question (an OTP) through `input_prompt` as a local job does.
|
||||
- **Remote services.** A full-mode server can run a service through one of its own `remote_services` servers (see [Remote sessions](remote-sessions.md)). `GET /api/config` lists their names in `remote_services`, and `GET /api/services?remote=<name>` lists that server's services, each with `remote` set to the name. Add `"remote": "<name>"` to `POST /api/search`, `/api/list-titles`, `/api/list-tracks` or `/api/download`, and the server opens a remote session with its own key for that server: the remote logs in and resolves titles, tracks and licences, and a download still runs, decrypts and muxes here. The tag may be any case or an alias, and your allowlist applies to it. An unknown name is `400 INVALID_PARAMETERS`, a server that does not answer is `SERVICE_UNAVAILABLE`, and a tag it does not offer is `INVALID_SERVICE`. List calls from the same API key for the same title, profile, proxy, client region and service options share one remote session, which closes after 120 seconds unused. When the server stops, a list call that waits on the login of a new remote session, or starts one, gets `SERVER_DRAINING` (409). A call that opens a lost remote session again can be cut too: `list-titles` then gets `SERVER_DRAINING`, and `list-tracks` that or `SERVICE_ERROR` (422). An optional `client_name` names your client on the remote server's dashboard as `serve (<client_name>)`. A relayed search opens no remote session. The server sends its own credentials, cookies and cache for the `profile` with the search. A service that searches with no login gets none of them. A `--remote-only` server does not relay. A remote login that waits on you (a pair code or URL to approve on another device) cannot answer through a list call, so poll `GET /api/remote/logins` alongside it: each entry carries the login's `notice`, its `qr` (the text of a QR code to scan, or null), and its `prompt` when it asks a question (an OTP), which you answer with `POST /api/remote/logins/{id}/input` and `{"response": "..."}`. A remote download job shows the same text as its own `notice`, and asks a question (an OTP) through `input_prompt` as a local job does.
|
||||
|
||||
!!! warning "Error responses have two shapes"
|
||||
Structured application errors (raised inside a handler) return `{"status": "error", "error_code": "...", "message": "...", "timestamp": "..."}`. The authentication middleware, however, returns a **different** shape: `{"status": 401, "message": "..."}` with an integer `status` and no `error_code`. The same middleware answers `429` in that shape when an API key goes over its rate limit. Clients must accept both shapes. The [Error responses](#error-responses) section at the bottom of this page gives the full error model.
|
||||
|
||||
@@ -127,7 +127,7 @@ while the server restarts.
|
||||
| `SESSION_NOT_FOUND` | 404 | The remote-dl session does not exist or has expired. |
|
||||
| `TRACK_NOT_FOUND` | 404 | A referenced track ID is not present in the remote session. |
|
||||
| `CONFLICT` | 409 | The target resource is in a state that disallows the action (retrying a running job, prioritising a non-queued job, clearing cache during an active download). |
|
||||
| `SERVER_DRAINING` | 409 | The server is about to restart and starts no new remote session or download job. Open work continues. Retryable after the restart. A `dl --remote` client waits for the restart and opens a new remote session. |
|
||||
| `SERVER_DRAINING` | 409 | The server is about to restart or stops, and starts no new remote session, remote login or download job. Open work continues. Retryable after the restart. A `dl --remote` client waits for the restart and opens a new remote session. |
|
||||
| `SERVICE_ERROR` | 422 | The streaming service's API returned an error, or the service does not support the requested operation, or the service code exited (`sys.exit`). |
|
||||
| `DRM_ERROR` | 422 | DRM or license acquisition failed. |
|
||||
| `RATE_LIMITED` | 429 | The streaming service is rate-limiting requests. Retryable. |
|
||||
|
||||
@@ -643,6 +643,12 @@ Source: `unshackle/core/api/session_store.py`. A singleton you get from
|
||||
remote session 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 tracked task that still runs, and stops the sweep.
|
||||
Within that time, a login that ends deletes its cache directory again.
|
||||
- **Relay.** A server that relays to a `remote_services` server runs **`end_remote_pool()`** after `close_channels()`.
|
||||
It starts the end of each remote login that waits, and of all idle pooled remote sessions at the same time. A list
|
||||
call whose login it ends, or whose login comes later, gets `SERVER_DRAINING`. A request in flight finishes first. Every
|
||||
5 seconds until it has stopped, the server ends each request that opens its lost remote session again. Then
|
||||
**`close_remote_pool()`** ends the rest and waits up to 5 seconds for each `DELETE` request. The exit of the process
|
||||
waits for an end that still runs.
|
||||
- **Signals.** The first `SIGTERM` starts the shutdown, and the server ignores each later one. A second Ctrl+C forces
|
||||
the end. On Windows only Ctrl+C starts the shutdown.
|
||||
|
||||
@@ -817,6 +823,7 @@ saves the returned cache and then stops the tunnel. It does so:
|
||||
- when a signal or a closed console stops the process, or the cancel of a download job stops its worker
|
||||
- when the login or any other step of the opening fails, or `create` times out or its answer is cut off
|
||||
- when a serve that relays for a REST client closes its pooled remote session
|
||||
- when such a serve stops: each remote login that waits, and all idle pooled remote sessions at the same time
|
||||
|
||||
The `DELETE` has a connect and read timeout of 15s each. The client sends it again only once, when a gateway answers with
|
||||
an error page or asks for the API key in the other header. It does not wait for a rate limit.
|
||||
|
||||
Reference in New Issue
Block a user