Coverage / crates/hub/src/shutdown.rs 80.0%
36 of 45 lines run, 12 of 22 functions · run #482 on proposal/333 · run missed
| 1 | //! Stopping without cutting anyone off (oxygenhub#233). On SIGTERM (a | |
| 2 | //! `systemctl restart`) or Ctrl-C the hub stops taking connections, ends | |
| 3 | //! its event streams (browsers reconnect by themselves), and gives the | |
| 4 | //! requests in flight up to `DRAIN` to finish. Given a listening socket by | |
| 5 | //! systemd (socket activation, docs/deploy.md), it serves that rather than | |
| 6 | //! binding: the socket outlives the restart, so a request that arrives | |
| 7 | //! between the old process and the new one waits in its queue instead of | |
| 8 | //! being refused. | |
| 9 | | |
| 10 | use OnceLock; | |
| 11 | use watch; | |
| 12 | ||
| 13 | /// How long the requests in flight get to finish. | |
| 14 | pub const DRAIN: Duration = from_secs; | |
| 15 | ||
| 16 | /// How long, after the drain, work still running on the runtime's | |
| 17 | /// blocking threads (a slow request's repository work, a bucket call) may | |
| 18 | /// hold the process. Dropping the runtime would wait for it however long | |
| 19 | /// it takes: on 2026-10-17 a restart stood a minute past "stopped", until | |
| 20 | /// systemd killed it. | |
| 21 | pub const EXIT_GRACE: Duration = from_secs; | |
| 22 | ||
| 23 | /// End the runtime once `serve` has returned, cutting off what still runs. | |
| 24 | 1× | |
| 25 | 1× | |
| 26 | 1× | |
| 27 | ||
| 28 | 7× | |
| 29 | | |
| 30 | 7× | |
| 31 | 7× | |
| 32 | ||
| 33 | /// Begin stopping. | |
| 34 | 1× | |
| 35 | 1× | |
| 36 | 1× | |
| 37 | ||
| 38 | 1× | |
| 39 | 1× | |
| 40 | 1× | |
| 41 | ||
| 42 | /// Done when the hub begins stopping: for event streams to end on, and for | |
| 43 | /// the servers' graceful shutdown. | |
| 44 | 5× | pub async |
| 45 | 5× | |
| 46 | 5× | |
| 47 | 2× | |
| 48 | ||
| 49 | /// Wait for SIGTERM or Ctrl-C, then begin stopping. Installed before the | |
| 50 | /// servers start, so a signal never kills the process outright. | |
| 51 | 1× | |
| 52 | | |
| 53 | 1× | |
| 54 | 1× | |
| 55 | | |
| 56 | 1× | |
| 57 | 1× | |
| 58 | 1× | |
| 59 | | |
| 60 | | |
| 61 | | |
| 62 | | |
| 63 | | |
| 64 | | |
| 65 | 0× | |
| 66 | 0× | |
| 67 | 1× | |
| 68 | ||
| 69 | /// The listening socket systemd passed (LISTEN_FDS, first descriptor 3), | |
| 70 | /// when it passed one to this process. | |
| 71 | 1× | |
| 72 | | |
| 73 | | |
| 74 | | |
| 75 | 1× | |
| 76 | 0× | |
| 77 | 0× | |
| 78 | 0× | |
| 79 | 0× | |
| 80 | | |
| 81 | | |
| 82 | 0× | |
| 83 | 0× | |
| 84 | 0× | |
| 85 | | |
| 86 | | |
| 87 | | |
| 88 | 1× | |
| 89 | ||
| 90 | | |
| 91 | | |
| 92 | | |
| 93 | | |
| 94 | | |
| 95 | 1× | |
| 96 | 1× | |
| 97 | 1× | |
| 98 | 1× | |
| 99 | 1× | |
| 100 | 1× | |
| 101 | 1× | |
| 102 | |