@fuzdev/fuz_app 0.184.0 → 0.185.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/dist/actions/CLAUDE.md +4 -1
  2. package/dist/actions/register_action_ws.d.ts +14 -7
  3. package/dist/actions/register_action_ws.d.ts.map +1 -1
  4. package/dist/actions/ws_socket_session.d.ts +17 -4
  5. package/dist/actions/ws_socket_session.d.ts.map +1 -1
  6. package/dist/actions/ws_socket_session.js +38 -6
  7. package/dist/auth/CLAUDE.md +7 -4
  8. package/dist/auth/audit_log_routes.d.ts +1 -1
  9. package/dist/auth/audit_log_routes.d.ts.map +1 -1
  10. package/dist/auth/audit_log_routes.js +3 -2
  11. package/dist/auth/cleanup.d.ts +34 -3
  12. package/dist/auth/cleanup.d.ts.map +1 -1
  13. package/dist/auth/cleanup.js +11 -3
  14. package/dist/http/CLAUDE.md +1 -1
  15. package/dist/http/pending_effects.d.ts +8 -4
  16. package/dist/http/pending_effects.d.ts.map +1 -1
  17. package/dist/http/route_spec.d.ts +3 -3
  18. package/dist/http/route_spec.d.ts.map +1 -1
  19. package/dist/realtime/audit_log_sse.d.ts +1 -1
  20. package/dist/realtime/sse.d.ts +2 -2
  21. package/dist/realtime/sse.d.ts.map +1 -1
  22. package/dist/realtime/sse_constants.d.ts +1 -1
  23. package/dist/realtime/sse_constants.js +1 -1
  24. package/dist/server/app_server.d.ts +59 -71
  25. package/dist/server/app_server.d.ts.map +1 -1
  26. package/dist/server/app_server.js +52 -60
  27. package/dist/server/shutdown_drain.d.ts +69 -0
  28. package/dist/server/shutdown_drain.d.ts.map +1 -0
  29. package/dist/server/shutdown_drain.js +77 -0
  30. package/dist/testing/CLAUDE.md +73 -41
  31. package/dist/testing/admin_integration.d.ts +2 -2
  32. package/dist/testing/admin_integration.d.ts.map +1 -1
  33. package/dist/testing/admin_integration.js +36 -20
  34. package/dist/testing/cross_backend/bootstrap_backend.d.ts +3 -1
  35. package/dist/testing/cross_backend/bootstrap_backend.d.ts.map +1 -1
  36. package/dist/testing/cross_backend/bootstrap_backend.js +5 -1
  37. package/dist/testing/cross_backend/create_dual_spawn_global_setup.d.ts +10 -1
  38. package/dist/testing/cross_backend/create_dual_spawn_global_setup.d.ts.map +1 -1
  39. package/dist/testing/cross_backend/create_dual_spawn_global_setup.js +33 -7
  40. package/dist/testing/cross_backend/in_process_setup.d.ts +1 -1
  41. package/dist/testing/cross_backend/in_process_setup.js +1 -1
  42. package/dist/testing/cross_backend/rpc_success_fixtures.d.ts.map +1 -1
  43. package/dist/testing/cross_backend/rpc_success_fixtures.js +2 -1
  44. package/dist/testing/cross_backend/spawn_backend.d.ts +14 -0
  45. package/dist/testing/cross_backend/spawn_backend.d.ts.map +1 -1
  46. package/dist/testing/cross_backend/spawn_backend.js +56 -8
  47. package/dist/testing/cross_backend/spine_suites.d.ts +17 -14
  48. package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
  49. package/dist/testing/cross_backend/spine_suites.js +33 -13
  50. package/dist/testing/cross_backend/standard.d.ts +18 -82
  51. package/dist/testing/cross_backend/standard.d.ts.map +1 -1
  52. package/dist/testing/cross_backend/standard.js +6 -21
  53. package/dist/testing/cross_backend/standard_auth.d.ts +74 -0
  54. package/dist/testing/cross_backend/standard_auth.d.ts.map +1 -0
  55. package/dist/testing/cross_backend/standard_auth.js +28 -0
  56. package/dist/testing/cross_backend/standard_bundle.d.ts +48 -0
  57. package/dist/testing/cross_backend/standard_bundle.d.ts.map +1 -0
  58. package/dist/testing/cross_backend/standard_bundle.js +43 -0
  59. package/dist/testing/cross_backend/testing_reset_actions.d.ts +11 -0
  60. package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
  61. package/dist/testing/cross_backend/testing_reset_actions.js +13 -0
  62. package/dist/testing/cross_backend/testing_server_bun.d.ts.map +1 -1
  63. package/dist/testing/cross_backend/testing_server_bun.js +5 -4
  64. package/dist/testing/cross_backend/testing_server_core.d.ts +16 -3
  65. package/dist/testing/cross_backend/testing_server_core.d.ts.map +1 -1
  66. package/dist/testing/cross_backend/testing_server_core.js +20 -4
  67. package/dist/testing/cross_backend/ts_spine_backend_config.d.ts +6 -2
  68. package/dist/testing/cross_backend/ts_spine_backend_config.d.ts.map +1 -1
  69. package/dist/testing/cross_backend/ts_spine_backend_config.js +7 -3
  70. package/dist/testing/error_coverage.d.ts +5 -0
  71. package/dist/testing/error_coverage.d.ts.map +1 -1
  72. package/dist/testing/error_coverage.js +2 -1
  73. package/dist/testing/integration.d.ts +4 -20
  74. package/dist/testing/integration.d.ts.map +1 -1
  75. package/dist/testing/integration.js +49 -79
  76. package/dist/testing/integration_helpers.d.ts +16 -0
  77. package/dist/testing/integration_helpers.d.ts.map +1 -1
  78. package/dist/testing/integration_helpers.js +29 -1
  79. package/dist/testing/middleware_gate_probes.d.ts +55 -1
  80. package/dist/testing/middleware_gate_probes.d.ts.map +1 -1
  81. package/dist/testing/middleware_gate_probes.js +69 -3
  82. package/dist/testing/test_app.d.ts +3 -2
  83. package/dist/testing/test_app.d.ts.map +1 -1
  84. package/dist/testing/test_app.js +5 -4
  85. package/package.json +1 -1
@@ -10,7 +10,6 @@
10
10
  import { Hono, type Context } from 'hono';
11
11
  import type { UpgradeWebSocket } from 'hono/ws';
12
12
  import type { AnySchema } from '@fuzdev/fuz_schema/schema.ts';
13
- import type { Logger } from '@fuzdev/fuz_util/log.ts';
14
13
  import type { BootstrapTokenStore } from '../auth/bootstrap_token_store.js';
15
14
  import { type EventSpec } from '../realtime/sse.js';
16
15
  import { type AuditLogSse } from '../realtime/audit_log_sse.js';
@@ -25,11 +24,11 @@ import { type AppSurfaceSpec, type AppSurfaceDiagnostic, type RpcEndpointSpec }
25
24
  import { type RouteSpec } from '../http/route_spec.js';
26
25
  import type { MiddlewareCarveOut, MiddlewareSpec } from '../http/middleware_spec.js';
27
26
  import { type BootstrapStatus } from '../auth/bootstrap_routes.js';
28
- import { type EffectErrorContext, type RequestTracker } from '../http/pending_effects.js';
27
+ import { type EffectErrorContext } from '../http/pending_effects.js';
29
28
  import { type WsEndpointSpec } from '../actions/ws_endpoint_spec.js';
30
29
  import type { ConnectionRegistry } from '../actions/connection_registry.js';
31
- import { type AuthCleanupScheduleOptions } from '../auth/cleanup.js';
32
- import type { AuditEmitter } from '../auth/audit_emitter.js';
30
+ import { type AuthCleanupSchedule } from '../auth/cleanup.js';
31
+ import { type ShutdownDrainGivenUp } from './shutdown_drain.js';
33
32
  /**
34
33
  * Bootstrap configuration for `AppServerOptions.bootstrap`.
35
34
  *
@@ -291,27 +290,34 @@ export interface AppServerOptions {
291
290
  keep_alive_ms?: number | null;
292
291
  };
293
292
  /**
294
- * Schedule the auth cleanup beside the server: `start_auth_cleanup` over
295
- * `backend.deps` — a pass as assembly finishes, then one per interval —
296
- * stopped by `AppServer.close`. Each pass deletes expired sessions and
297
- * closes the connections they opened through `deps.connection_closer`
298
- * (every WebSocket connection registry and audit stream this server mounts), and
299
- * audits each newly expired role_grant offer once.
293
+ * Whether the auth cleanup runs beside the server — required, with no
294
+ * default, so a server neither gets nor loses the sweeps without writing
295
+ * it out. `{every_ms}` runs `start_auth_cleanup` over `backend.deps` — a
296
+ * pass as assembly finishes, then one per `every_ms` — stopped by
297
+ * `AppServer.close` within its drain bound. Each pass deletes expired
298
+ * sessions and closes the connections they opened through
299
+ * `deps.connection_closer` (every WebSocket connection registry and audit
300
+ * stream this server mounts), and audits each newly expired role_grant
301
+ * offer once.
300
302
  *
301
- * **Off by default; a production server should turn it on.** Without it
302
- * nothing sweeps: expired session rows accumulate and an offer's expiry is
303
- * never audited. Connections do not depend on it — each closes at its
303
+ * **A production server passes
304
+ * `{every_ms: DEFAULT_AUTH_CLEANUP_INTERVAL_MS}`.** With `'off'` nothing
305
+ * sweeps: expired session rows accumulate and an offer's expiry is never
306
+ * audited. Connections do not depend on it — each closes at its
304
307
  * credential's deadline (`auth/credential_deadline.ts`), and the sweep's
305
- * close repeats that one. The Rust spine's servers all schedule the twin
306
- * (`spawn_auth_cleanup`).
308
+ * close repeats that one. Twin of the Rust spine's
309
+ * `AuthCleanupSchedule::Every`, which a server's backend options carry and
310
+ * its backend attaches as a `fuz_auth::AuthCleanup`.
307
311
  *
308
- * Pass `true` for the default interval
309
- * (`DEFAULT_AUTH_CLEANUP_INTERVAL_MS`), or `{interval_ms}` for another.
310
- * Leave it off in an in-process test harness — a background pass deletes
311
- * rows and writes audit rows mid-test — and in a process that runs
312
+ * `'off'` in an in-process test harness — a background pass deletes rows
313
+ * and writes audit rows mid-test — and in a process that runs
312
314
  * `run_auth_cleanup` on a schedule of its own.
315
+ *
316
+ * Checked with the other options, before assembly acquires anything:
317
+ * `every_ms` must be a positive finite number of ms no greater than
318
+ * `PERIODIC_INTERVAL_MS_MAX`.
313
319
  */
314
- auth_cleanup?: boolean | AuthCleanupScheduleOptions;
320
+ auth_cleanup: AuthCleanupSchedule;
315
321
  /** SSE event specs for surface generation. Defaults to `[]` (no SSE events). */
316
322
  event_specs?: Array<EventSpec>;
317
323
  /**
@@ -429,13 +435,13 @@ export interface AppServerOptions {
429
435
  */
430
436
  await_pending_effects?: boolean;
431
437
  /**
432
- * How long `AppServer.close` waits for the work still in flight — each
433
- * HTTP request and WS message accepted, until its handler has returned and
434
- * its effect queues (failure audit rows, API token usage, post-commit
435
- * thunks) have flushed, and every pool write of `deps.audit` — before it
436
- * closes the database. What is still running then is given up on and
437
- * logged. Default `DEFAULT_SHUTDOWN_DRAIN_TIMEOUT_MS`; must be a positive
438
- * number of ms.
438
+ * How long `AppServer.close` waits for the work still in flight — an auth
439
+ * cleanup pass in progress, each HTTP request and WS message accepted,
440
+ * until its handler has returned and its effect queues (failure audit
441
+ * rows, API token usage, post-commit thunks) have flushed, and every pool
442
+ * write of `deps.audit` — before it closes the database. What is still
443
+ * running then is given up on and logged. Default
444
+ * `DEFAULT_SHUTDOWN_DRAIN_TIMEOUT_MS`; must be a positive number of ms.
439
445
  */
440
446
  shutdown_drain_timeout_ms?: number;
441
447
  /**
@@ -477,9 +483,8 @@ export interface AppServer {
477
483
  /**
478
484
  * Shut the server's resources down, in order:
479
485
  *
480
- * 1. stop the auth cleanup schedule when the `auth_cleanup` option started
481
- * one, waiting for a pass in progress — that wait has no bound of its
482
- * own, so a shutdown with a deadline races it
486
+ * 1. stop the auth cleanup schedule when `auth_cleanup` started one: no
487
+ * pass starts from here, and a pass in progress is waited for in step 3
483
488
  * 2. close every live connection on `deps.connection_closer`
484
489
  * (`close_all_connections`) — each WebSocket with `WS_CLOSE_GOING_AWAY`, each
485
490
  * audit stream — including registries supplied through
@@ -489,16 +494,21 @@ export interface AppServer {
489
494
  * is left closing, so an upgrade or stream that registers afterward is
490
495
  * born closed — refused at once rather than outliving the server — and
491
496
  * a closed registry hosts no other server
492
- * 3. wait for the work still in flight on `deps.request_tracker` and
497
+ * 3. wait for the auth cleanup pass in progress, if any — JS cannot abort
498
+ * one, so at the bound it is given up on and left to finish against the
499
+ * closing database, where the Rust shutdown aborts its upkeep task —
500
+ * and for the work still in flight on `deps.request_tracker` and
493
501
  * `deps.audit`: every HTTP request and WS message accepted, until its
494
502
  * handler has returned and its effect queues have flushed (failure
495
503
  * audit rows, API token usage, post-commit thunks; production holds no
496
- * HTTP response for them, and a WS reply is sent before its flush), and
504
+ * HTTP response for them, and a WS reply is sent before its flush),
505
+ * every WebSocket still opening — its admission re-read, which step 2's
506
+ * close turns into a going-away refusal, and `on_socket_open` — and
497
507
  * every pool write of the emitter — a handler still running when the
498
508
  * close starts is waited for, then its flush. A WS handler's socket is
499
509
  * closed in step 2, which aborts its `signal`; one that runs on is still
500
- * waited for. Bounded by `shutdown_drain_timeout_ms`, logging what it
501
- * gives up on. From here a request that arrives is refused — HTTP with
510
+ * waited for. One bound for all of it, `shutdown_drain_timeout_ms`,
511
+ * logging what it gives up on. From here a request that arrives is refused — HTTP with
502
512
  * 503 `service_unavailable`, and a WS message, on a socket step 2
503
513
  * didn't end (a hand mount), with the `service_unavailable` JSON-RPC
504
514
  * error — never run against the closing database. The Rust
@@ -520,17 +530,23 @@ export interface AppServer {
520
530
  * host another server
521
531
  * 5. close the database connection (`AppBackend.close`)
522
532
  *
523
- * Idempotent: a second call settles with the first one's outcome (a failed
524
- * close is not retried), and concurrent calls share one shutdown. Never
525
- * await it from a handler: its own request is held, so the drain waits on
526
- * it until `shutdown_drain_timeout_ms`.
533
+ * Resolves what step 3 gave up on at its bound, every count `0` when it
534
+ * drained everything; `shutdown_gave_up` reads it. A process that serves
535
+ * the app reports a give-up as a failed exit, as the Rust spine's
536
+ * `StartupError::ShutdownGivenUp` does.
537
+ *
538
+ * Idempotent: a second call settles with the first one's outcome — the
539
+ * same report, or the same rejection (a failed close is not retried) — and
540
+ * concurrent calls share one shutdown. Never await it from a handler: its
541
+ * own request is held, so the drain waits on it until
542
+ * `shutdown_drain_timeout_ms`.
527
543
  *
528
544
  * Stop accepting new HTTP connections first — without awaiting the
529
545
  * listener's full drain, since live WebSockets hold it open until `close`
530
546
  * ends them — so no new request reaches a closed database. A request the
531
547
  * app already accepted is waited for in step 3.
532
548
  */
533
- close: () => Promise<void>;
549
+ close: () => Promise<ShutdownDrainGivenUp>;
534
550
  }
535
551
  /**
536
552
  * Assert that `audit_sse` was wired by `create_app_server` and return it
@@ -557,12 +573,6 @@ export declare const require_audit_sse: (source: {
557
573
  * `fuz_http` `DEFAULT_BODY_LIMIT_BYTES`.
558
574
  */
559
575
  export declare const DEFAULT_BODY_LIMIT_BYTES: number;
560
- /**
561
- * Default bound on `AppServer.close`'s wait for the effects still in flight
562
- * (`AppServerOptions.shutdown_drain_timeout_ms`). Twin of the Rust spine's
563
- * `DEFAULT_DRAIN_TIMEOUT`.
564
- */
565
- export declare const DEFAULT_SHUTDOWN_DRAIN_TIMEOUT_MS = 10000;
566
576
  /**
567
577
  * Each `AppServerOptions` rate-limiter field, with the defaults an omitted one
568
578
  * is built from under `rate_limiters: 'enforced'` and the name its
@@ -703,41 +713,19 @@ export declare const collect_config_diagnostics: (input: ConfigDiagnosticsInput)
703
713
  * so far runs, last acquired first (one that throws is logged and the rest
704
714
  * still run), and the original error is rethrown: a failed assembly leaves
705
715
  * the backend's emitter, closer and notification sender as it found them and
706
- * no limiter timer running. When `auth_cleanup` is set, the
716
+ * no limiter timer running. When `auth_cleanup` is `{every_ms}`, the
707
717
  * auth cleanup schedule starts as the last step of assembly — nothing after
708
718
  * it can throw, so an assembly that throws leaves no schedule running.
709
719
  *
710
720
  * The returned `close` owns shutdown: it stops that schedule, closes every
711
- * live connection on the backend's closer, runs the same releases, and
712
- * closes the database (`AppServer.close`).
721
+ * live connection on the backend's closer, waits for the work in flight
722
+ * within its bound, runs the same releases, closes the database, and
723
+ * resolves what the wait gave up on (`AppServer.close`).
713
724
  *
714
725
  * @returns the assembled Hono app with its surface, bootstrap status, migration results,
715
726
  * audit SSE, mounted WS registries, and `close`
716
727
  * @throws Error from any assembly step, after releasing what assembly acquired
717
728
  */
718
729
  export declare const create_app_server: (options: AppServerOptions) => Promise<AppServer>;
719
- /**
720
- * What `drain_effects_on_shutdown` gave up on at its bound, each counted on
721
- * its own: a request still waiting on its audit writes has those writes
722
- * counted in `audit_writes` too, so the two are not summed.
723
- */
724
- export interface ShutdownDrainGivenUp {
725
- /**
726
- * Requests still held — HTTP requests and WS messages alike, each with its
727
- * handler or its effect flush still running.
728
- */
729
- requests: number;
730
- /** Pool writes of the audit emitter still in flight. */
731
- audit_writes: number;
732
- }
733
- /**
734
- * Wait for the requests held (HTTP requests and WS messages, one tracker —
735
- * each until its handler has returned and its flush settled) and then the
736
- * audit emitter's pool writes, until none is left or `timeout_ms` passes —
737
- * then log an error naming what was given up on. Never rejects.
738
- *
739
- * @returns what was given up on, both counts `0` when everything settled
740
- */
741
- export declare const drain_effects_on_shutdown: (requests: Pick<RequestTracker, "drain_inflight" | "inflight_count">, audit: Pick<AuditEmitter, "drain_inflight" | "inflight_count">, timeout_ms: number, log: Logger) => Promise<ShutdownDrainGivenUp>;
742
730
  export {};
743
731
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AC,KACxE,oBAkBF,CAAC;AAEF;;;;GAIG;AACH,MAAM,WAAW,sBAAsB;IACtC,2CAA2C;IAC3C,iBAAiB,EAAE,eAAe,CAAC;IACnC,2DAA2D;IAC3D,aAAa,EAAE,MAAM,CAAC,uBAAuB,EAAE,WAAW,GAAG,IAAI,CAAC,CAAC;IACnE,uFAAuF;IACvF,aAAa,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;CACzC;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,0BAA0B,GACtC,OAAO,sBAAsB,KAC3B,KAAK,CAAC,oBAAoB,CAgC5B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,eAAO,MAAM,iBAAiB,GAAU,SAAS,gBAAgB,KAAG,OAAO,CAAC,SAAS,CAQpF,CAAC"}
@@ -43,6 +43,8 @@ import { register_action_ws } from '../actions/register_action_ws.js';
43
43
  import { resolve_ws_endpoints } from '../actions/ws_endpoint_spec.js';
44
44
  import { create_revocation_guard } from '../actions/connection_closer.js';
45
45
  import { start_auth_cleanup } from '../auth/cleanup.js';
46
+ import { PERIODIC_INTERVAL_MS_MAX } from '../periodic.js';
47
+ import { DEFAULT_SHUTDOWN_DRAIN_TIMEOUT_MS, drain_effects_on_shutdown } from './shutdown_drain.js';
46
48
  /**
47
49
  * Assert that `audit_sse` was wired by `create_app_server` and return it
48
50
  * as a non-null `AuditLogSse`. Throws a labelled error when the
@@ -71,12 +73,6 @@ export const require_audit_sse = (source) => {
71
73
  * `fuz_http` `DEFAULT_BODY_LIMIT_BYTES`.
72
74
  */
73
75
  export const DEFAULT_BODY_LIMIT_BYTES = 1024 * 1024;
74
- /**
75
- * Default bound on `AppServer.close`'s wait for the effects still in flight
76
- * (`AppServerOptions.shutdown_drain_timeout_ms`). Twin of the Rust spine's
77
- * `DEFAULT_DRAIN_TIMEOUT`.
78
- */
79
- export const DEFAULT_SHUTDOWN_DRAIN_TIMEOUT_MS = 10_000;
80
76
  /**
81
77
  * Each `AppServerOptions` rate-limiter field, with the defaults an omitted one
82
78
  * is built from under `rate_limiters: 'enforced'` and the name its
@@ -220,13 +216,14 @@ export const collect_config_diagnostics = (input) => {
220
216
  * so far runs, last acquired first (one that throws is logged and the rest
221
217
  * still run), and the original error is rethrown: a failed assembly leaves
222
218
  * the backend's emitter, closer and notification sender as it found them and
223
- * no limiter timer running. When `auth_cleanup` is set, the
219
+ * no limiter timer running. When `auth_cleanup` is `{every_ms}`, the
224
220
  * auth cleanup schedule starts as the last step of assembly — nothing after
225
221
  * it can throw, so an assembly that throws leaves no schedule running.
226
222
  *
227
223
  * The returned `close` owns shutdown: it stops that schedule, closes every
228
- * live connection on the backend's closer, runs the same releases, and
229
- * closes the database (`AppServer.close`).
224
+ * live connection on the backend's closer, waits for the work in flight
225
+ * within its bound, runs the same releases, closes the database, and
226
+ * resolves what the wait gave up on (`AppServer.close`).
230
227
  *
231
228
  * @returns the assembled Hono app with its surface, bootstrap status, migration results,
232
229
  * audit SSE, mounted WS registries, and `close`
@@ -243,40 +240,28 @@ export const create_app_server = async (options) => {
243
240
  }
244
241
  };
245
242
  /**
246
- * Wait for the requests held (HTTP requests and WS messages, one tracker —
247
- * each until its handler has returned and its flush settled) and then the
248
- * audit emitter's pool writes, until none is left or `timeout_ms` passes —
249
- * then log an error naming what was given up on. Never rejects.
243
+ * Read `auth_cleanup`: `null` for `'off'`, else its `every_ms`.
250
244
  *
251
- * @returns what was given up on, both counts `0` when everything settled
245
+ * @throws Error unless it is `'off'` or `{every_ms}` with a positive finite
246
+ * number no greater than `PERIODIC_INTERVAL_MS_MAX`
252
247
  */
253
- export const drain_effects_on_shutdown = async (requests, audit, timeout_ms, log) => {
254
- const drain = async () => {
255
- // until both are empty: a flush's post-commit thunk can start an audit
256
- // write, and a request accepted meanwhile is held too
257
- do {
258
- await requests.drain_inflight();
259
- await audit.drain_inflight();
260
- } while (requests.inflight_count() > 0 || audit.inflight_count() > 0);
261
- };
262
- let timer;
263
- const timed_out = new Promise((resolve) => {
264
- timer = setTimeout(resolve, timeout_ms);
265
- });
266
- try {
267
- await Promise.race([drain(), timed_out]);
268
- }
269
- finally {
270
- clearTimeout(timer);
248
+ const parse_auth_cleanup = (auth_cleanup) => {
249
+ if (auth_cleanup === 'off')
250
+ return null;
251
+ const every_ms = typeof auth_cleanup === 'object' &&
252
+ auth_cleanup !== null &&
253
+ Object.hasOwn(auth_cleanup, 'every_ms')
254
+ ? auth_cleanup.every_ms
255
+ : undefined;
256
+ if (typeof every_ms === 'number' &&
257
+ Number.isFinite(every_ms) &&
258
+ every_ms > 0 &&
259
+ every_ms <= PERIODIC_INTERVAL_MS_MAX) {
260
+ return every_ms;
271
261
  }
272
- const given_up = {
273
- requests: requests.inflight_count(),
274
- audit_writes: audit.inflight_count()
275
- };
276
- if (given_up.requests === 0 && given_up.audit_writes === 0)
277
- return given_up;
278
- log.error(`create_app_server: shutdown gave up after ${timeout_ms}ms on work still running — ${given_up.requests} request(s) (handler or effect flush), ${given_up.audit_writes} audit row write(s)`);
279
- return given_up;
262
+ throw new Error(`create_app_server: auth_cleanup must be 'off' or {every_ms} with a positive finite number of ms no greater than ${PERIODIC_INTERVAL_MS_MAX}, got ${typeof auth_cleanup === 'object' && auth_cleanup !== null
263
+ ? JSON.stringify(auth_cleanup, (_key, value) => typeof value === 'number' && !Number.isFinite(value) ? String(value) : value)
264
+ : String(auth_cleanup)}`);
280
265
  };
281
266
  /**
282
267
  * Run `releases` last-first and empty it. Each runs in its own `try`, so one
@@ -329,6 +314,11 @@ const assemble_app_server = async (options, releases) => {
329
314
  if (!(shutdown_drain_timeout_ms > 0 && Number.isFinite(shutdown_drain_timeout_ms))) {
330
315
  throw new Error(`create_app_server: shutdown_drain_timeout_ms must be a positive number of ms, got ${shutdown_drain_timeout_ms}`);
331
316
  }
317
+ // the schedule starts last, so its interval is refused here, before
318
+ // anything is acquired — as the Rust backend build refuses a zero `Every`
319
+ // first. A caller of the old option shape (`true`, `{interval_ms}`) lands
320
+ // here too, rather than on a schedule it didn't name.
321
+ const auth_cleanup_every_ms = parse_auth_cleanup(options.auth_cleanup);
332
322
  // Rate limiters — the ones built here are the server's to dispose, on
333
323
  // close or when assembly fails.
334
324
  const { mode: rate_limiter_mode, limiters: rate_limiters, built: built_rate_limiters } = resolve_rate_limiters(options);
@@ -383,9 +373,9 @@ const assemble_app_server = async (options, releases) => {
383
373
  // The daemon-token keeper, after the migrations and before the bootstrap
384
374
  // check, as the Rust spine's boot runs `resolve_keeper_into`: a live
385
375
  // bootstrap sets it on a fresh database once it commits, and this covers
386
- // one already bootstrapped. Best-effort, as there: a failed read leaves it
387
- // unset, and a keeper-less state authenticates no daemon token (the warn
388
- // below has no twin; the Rust spine's failed read is silent).
376
+ // one already bootstrapped. Best-effort, as there: a failed read warns
377
+ // (the same message as the Rust twin's) and leaves it unset, and a
378
+ // keeper-less state authenticates no daemon token.
389
379
  const daemon_token_state = options.daemon_token_state;
390
380
  if (daemon_token_state && daemon_token_state.keeper_account_id === null) {
391
381
  try {
@@ -727,20 +717,19 @@ const assemble_app_server = async (options, releases) => {
727
717
  // the 404 — read from the app's own router, so every route registered on
728
718
  // it counts, one added after assembly included
729
719
  app.notFound(create_unmatched_route_handler(app.router));
730
- // Auth cleanup — opt-in, and last: nothing after it can throw, so a failed
731
- // assembly never leaves a schedule running. Its own throw (an invalid
732
- // `interval_ms`) comes before any pass starts, and unwinds `releases` like
733
- // any other. Its closes go through `deps.connection_closer`, which the
734
- // mounts above have filled.
735
- const auth_cleanup = options.auth_cleanup
736
- ? start_auth_cleanup(deps, options.auth_cleanup === true ? undefined : options.auth_cleanup)
737
- : null;
720
+ // Auth cleanup — last: nothing after it can throw, so a failed assembly
721
+ // never leaves a schedule running, and its interval was checked with the
722
+ // other options, so it cannot throw either. Its closes go through
723
+ // `deps.connection_closer`, which the mounts above have filled.
724
+ const auth_cleanup = auth_cleanup_every_ms === null
725
+ ? null
726
+ : start_auth_cleanup(deps, { interval_ms: auth_cleanup_every_ms });
738
727
  // One shutdown, shared by every call — see `AppServer.close` for the order.
739
728
  let closing = null;
740
729
  const shutdown = async () => {
741
- // the schedule first, so a pass in progress finishes on a live pool
742
- if (auth_cleanup)
743
- await auth_cleanup.stop();
730
+ // the schedule first: no pass starts from here, and the one in progress
731
+ // is waited for in the drain below, under its bound
732
+ const upkeep = auth_cleanup ? [auth_cleanup.stop()] : [];
744
733
  // then the connections, so none outlives the server — a failure here
745
734
  // must not keep the database open
746
735
  try {
@@ -750,17 +739,20 @@ const assemble_app_server = async (options, releases) => {
750
739
  log.error('create_app_server: closing live connections on shutdown failed:', error);
751
740
  }
752
741
  // then the work still in flight, refusing any request that arrives from
753
- // here, so a handler still running, and the failure row, token-usage
754
- // touch or post-commit thunk a request or WS message started, is not cut
755
- // off by the closing pool — bounded. The Rust spine's drain waits for an
756
- // HTTP request already dispatched too, but drops a WS message's dispatch
757
- // still in its handler (`http/CLAUDE.md` §Pending Effects)
742
+ // here, so the cleanup pass, a handler still running, a WS upgrade's
743
+ // admission re-read,
744
+ // and the failure row, token-usage touch or post-commit thunk a request
745
+ // or WS message started, is not cut off by the closing pool — bounded.
746
+ // The Rust spine's drain waits for an HTTP request already dispatched
747
+ // too, but drops a WS message's dispatch still in its handler
748
+ // (`http/CLAUDE.md` §Pending Effects)
758
749
  request_tracker.close();
759
- await drain_effects_on_shutdown(request_tracker, deps.audit, shutdown_drain_timeout_ms, log);
750
+ const given_up = await drain_effects_on_shutdown(request_tracker, deps.audit, upkeep, shutdown_drain_timeout_ms, log);
760
751
  // then what assembly acquired — the audit listeners and closer members
761
752
  // this server added, and the limiters it built
762
753
  run_releases(releases, log, 'shutdown');
763
754
  await backend.close();
755
+ return given_up;
764
756
  };
765
757
  return {
766
758
  app,
@@ -0,0 +1,69 @@
1
+ /**
2
+ * The bounded wait `AppServer.close` makes for the work still in flight, and
3
+ * the report of what it gave up on.
4
+ *
5
+ * Its own module, free of any server framework, so a process that serves the
6
+ * app (`testing/cross_backend/testing_server_core.ts`) reads the report
7
+ * without loading the server. Twin of the Rust spine's shutdown drain
8
+ * (`fuz_http::serve_with_shutdown` and its `ServeShutdown`).
9
+ *
10
+ * @module
11
+ */
12
+ import type { Logger } from '@fuzdev/fuz_util/log.ts';
13
+ import type { RequestTracker } from '../http/pending_effects.js';
14
+ import type { AuditEmitter } from '../auth/audit_emitter.js';
15
+ /**
16
+ * Default bound on `AppServer.close`'s wait for the effects still in flight
17
+ * (`AppServerOptions.shutdown_drain_timeout_ms`). Twin of the Rust spine's
18
+ * `DEFAULT_DRAIN_TIMEOUT`.
19
+ */
20
+ export declare const DEFAULT_SHUTDOWN_DRAIN_TIMEOUT_MS = 10000;
21
+ /**
22
+ * What `AppServer.close` gave up on at its drain bound
23
+ * (`drain_effects_on_shutdown`), each counted on its own: a request still
24
+ * waiting on its audit writes has those writes counted in `audit_writes` too,
25
+ * so the counts are not summed. Every count `0` is a shutdown that drained
26
+ * everything. Twin of the Rust spine's `fuz_http::ServeShutdown`.
27
+ */
28
+ export interface ShutdownDrainGivenUp {
29
+ /**
30
+ * Requests still held — HTTP requests and WS messages alike, each with its
31
+ * handler or its effect flush still running, and WS upgrades still opening.
32
+ */
33
+ requests: number;
34
+ /** Pool writes of the audit emitter still in flight. */
35
+ audit_writes: number;
36
+ /**
37
+ * Upkeep tasks still running — the auth cleanup pass in progress when
38
+ * `auth_cleanup` scheduled one. Twin of `ServeShutdown`'s
39
+ * `upkeep_given_up`; here the pass is left to finish rather than aborted.
40
+ */
41
+ upkeep: number;
42
+ }
43
+ /**
44
+ * Whether a shutdown gave up on anything — its drain bound ran out before
45
+ * every wait finished. A process reports it as a failed exit. Twin of the
46
+ * Rust `ServeShutdown::gave_up`.
47
+ *
48
+ * @param report - what `AppServer.close` resolved
49
+ */
50
+ export declare const shutdown_gave_up: (report: ShutdownDrainGivenUp) => boolean;
51
+ /**
52
+ * Wait for the upkeep stops (the auth cleanup's pass in progress), then the
53
+ * requests held (HTTP requests, WS messages and WS upgrades still opening,
54
+ * one tracker — each until its handler has returned and its flush settled)
55
+ * and then the audit emitter's pool writes, until none is left or
56
+ * `timeout_ms` passes — then log an error naming what was given up on. One
57
+ * bound for all of it. Never rejects. The Rust shutdown joins its upkeep after
58
+ * the request drain; both wait concurrently against one deadline, so only the
59
+ * wait order differs.
60
+ *
61
+ * @param requests - the request tracker
62
+ * @param audit - the audit emitter
63
+ * @param upkeep - each upkeep task's stop, already requested; one still pending at the bound is counted
64
+ * @param timeout_ms - the bound
65
+ * @param log - where a give-up is logged
66
+ * @returns what was given up on, every count `0` when everything settled
67
+ */
68
+ export declare const drain_effects_on_shutdown: (requests: Pick<RequestTracker, "drain_inflight" | "inflight_count">, audit: Pick<AuditEmitter, "drain_inflight" | "inflight_count">, upkeep: ReadonlyArray<Promise<void>>, timeout_ms: number, log: Logger) => Promise<ShutdownDrainGivenUp>;
69
+ //# sourceMappingURL=shutdown_drain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shutdown_drain.d.ts","sourceRoot":"","sources":["../../src/lib/server/shutdown_drain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAE7D;;;;GAIG;AACH,eAAO,MAAM,iCAAiC,QAAS,CAAC;AAExD;;;;;;GAMG;AACH,MAAM,WAAW,oBAAoB;IACpC;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB,wDAAwD;IACxD,YAAY,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,MAAM,EAAE,MAAM,CAAC;CACf;AAED;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,GAAI,QAAQ,oBAAoB,KAAG,OACI,CAAC;AAErE;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,yBAAyB,GACrC,UAAU,IAAI,CAAC,cAAc,EAAE,gBAAgB,GAAG,gBAAgB,CAAC,EACnE,OAAO,IAAI,CAAC,YAAY,EAAE,gBAAgB,GAAG,gBAAgB,CAAC,EAC9D,QAAQ,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,EACpC,YAAY,MAAM,EAClB,KAAK,MAAM,KACT,OAAO,CAAC,oBAAoB,CAoC9B,CAAC"}
@@ -0,0 +1,77 @@
1
+ /**
2
+ * The bounded wait `AppServer.close` makes for the work still in flight, and
3
+ * the report of what it gave up on.
4
+ *
5
+ * Its own module, free of any server framework, so a process that serves the
6
+ * app (`testing/cross_backend/testing_server_core.ts`) reads the report
7
+ * without loading the server. Twin of the Rust spine's shutdown drain
8
+ * (`fuz_http::serve_with_shutdown` and its `ServeShutdown`).
9
+ *
10
+ * @module
11
+ */
12
+ /**
13
+ * Default bound on `AppServer.close`'s wait for the effects still in flight
14
+ * (`AppServerOptions.shutdown_drain_timeout_ms`). Twin of the Rust spine's
15
+ * `DEFAULT_DRAIN_TIMEOUT`.
16
+ */
17
+ export const DEFAULT_SHUTDOWN_DRAIN_TIMEOUT_MS = 10_000;
18
+ /**
19
+ * Whether a shutdown gave up on anything — its drain bound ran out before
20
+ * every wait finished. A process reports it as a failed exit. Twin of the
21
+ * Rust `ServeShutdown::gave_up`.
22
+ *
23
+ * @param report - what `AppServer.close` resolved
24
+ */
25
+ export const shutdown_gave_up = (report) => report.requests > 0 || report.audit_writes > 0 || report.upkeep > 0;
26
+ /**
27
+ * Wait for the upkeep stops (the auth cleanup's pass in progress), then the
28
+ * requests held (HTTP requests, WS messages and WS upgrades still opening,
29
+ * one tracker — each until its handler has returned and its flush settled)
30
+ * and then the audit emitter's pool writes, until none is left or
31
+ * `timeout_ms` passes — then log an error naming what was given up on. One
32
+ * bound for all of it. Never rejects. The Rust shutdown joins its upkeep after
33
+ * the request drain; both wait concurrently against one deadline, so only the
34
+ * wait order differs.
35
+ *
36
+ * @param requests - the request tracker
37
+ * @param audit - the audit emitter
38
+ * @param upkeep - each upkeep task's stop, already requested; one still pending at the bound is counted
39
+ * @param timeout_ms - the bound
40
+ * @param log - where a give-up is logged
41
+ * @returns what was given up on, every count `0` when everything settled
42
+ */
43
+ export const drain_effects_on_shutdown = async (requests, audit, upkeep, timeout_ms, log) => {
44
+ let upkeep_pending = upkeep.length;
45
+ const drain = async () => {
46
+ // the upkeep first, so a write a pass started is in the loop below
47
+ await Promise.all(upkeep.map(async (stopped) => {
48
+ await stopped;
49
+ upkeep_pending--;
50
+ }));
51
+ // until both are empty: a flush's post-commit thunk can start an audit
52
+ // write, and a request accepted meanwhile is held too
53
+ do {
54
+ await requests.drain_inflight();
55
+ await audit.drain_inflight();
56
+ } while (requests.inflight_count() > 0 || audit.inflight_count() > 0);
57
+ };
58
+ let timer;
59
+ const timed_out = new Promise((resolve) => {
60
+ timer = setTimeout(resolve, timeout_ms);
61
+ });
62
+ try {
63
+ await Promise.race([drain(), timed_out]);
64
+ }
65
+ finally {
66
+ clearTimeout(timer);
67
+ }
68
+ const given_up = {
69
+ requests: requests.inflight_count(),
70
+ audit_writes: audit.inflight_count(),
71
+ upkeep: upkeep_pending
72
+ };
73
+ if (!shutdown_gave_up(given_up))
74
+ return given_up;
75
+ log.error(`create_app_server: shutdown gave up after ${timeout_ms}ms on work still running — ${given_up.requests} request(s) (handler, effect flush, or WS open), ${given_up.audit_writes} audit row write(s), ${given_up.upkeep} upkeep task(s)`);
76
+ return given_up;
77
+ };