fix(remote): end the remote session when a signal or a closed console stops the client

This commit is contained in:
imSp4rky
2026-11-30 17:29:35 -07:00
parent ffe812f054
commit bafce963d3
14 changed files with 1225 additions and 31 deletions
+19 -3
View File
@@ -808,13 +808,13 @@ saves the returned cache and then stops the tunnel. It does so:
- when `dl` has finished every title, before the run post-scripts
- when the process exits: `--list`, an error, or Ctrl+C in any step, also before `create` answers
- 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
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. A process that ends without its exit hooks (`SIGHUP`,
`SIGTERM`, `SIGKILL`, a closed console window) sends no `DELETE`, so the remote session stays until its TTL. Ctrl+C
waits for the download threads before it ends the remote session.
an error page or asks for the API key in the other header. It does not wait for a rate limit. A Ctrl+C waits for the
download threads before it ends the remote session.
While the client ends a remote session, it ignores the first Ctrl+C, so it does not lose the returned cache. The next
Ctrl+C stops the wait at once, and the process then waits for no other end. The count of Ctrl+C is one for the process.
@@ -822,6 +822,22 @@ When the run itself called the end, after the last title, that Ctrl+C also stops
counts when the network read that blocks returns, so the 15s timeout limits the wait. After the end, no thread of the
client opens a remote session again.
`SIGHUP` (a closed terminal) and `SIGTERM` stop `dl`, `search` and `tunnel-test` as Ctrl+C does, with an exit code other
than 0. Three things are different:
- The `DELETE` goes first: before the wait for the download threads, for a CDM call and for the channel.
- The process ends 8s after the first signal at the latest, also when the server does not answer.
- A later signal changes nothing, and Ctrl+C keeps its own count.
After `SIGHUP` the process writes nothing more to a terminal. A redirected output gets each line. `nohup` keeps its effect.
Source: `unshackle/core/process_exit.py`.
On Windows, a closed console window and Ctrl+Break send the `DELETE` and then end the process, without the rest of the
Ctrl+C steps. The system gives a closed window about 5s. A kill (`SIGKILL`, a Windows task end, the cancel of a download
job on Windows) sends no `DELETE`, so only the server ends the remote session, at its own limits.
A cancelled job that uses a remote server sends the `DELETE` for at most 4s, then its worker ends.
The `DELETE` can arrive while the server still works on `create`. The server then answers `200` with no cache, and
the `create` makes no remote session, starts no login and answers `404 SESSION_NOT_FOUND`.