test(connection): make reconnect hardening deterministic
Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
b603bacfd0
commit
68b85b9050
4 files changed
+29
-24
No files matched your search
@@ -0,0 +1,13 @@
|
||||
import { expect, it } from "@effect/vitest";
|
||||
|
||||
import { bunWebSocketOptions } from "./httpServerOptions.ts";
|
||||
|
||||
it("reaps Bun websocket connections after six missed client ping windows", () => {
|
||||
expect(bunWebSocketOptions).toEqual({
|
||||
perMessageDeflate: {
|
||||
compress: "dedicated",
|
||||
decompress: "shared",
|
||||
},
|
||||
idleTimeout: 30,
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
export const bunWebSocketOptions = {
|
||||
// Negotiate permessage-deflate with clients that offer it. A dedicated
|
||||
// compressor keeps a per-connection sliding window, while the shared
|
||||
// decompressor avoids uWebSockets' dedicated-decompressor aborts.
|
||||
perMessageDeflate: {
|
||||
compress: "dedicated",
|
||||
decompress: "shared",
|
||||
},
|
||||
// RPC clients ping every 5s. Reaping a connection after six missed ping
|
||||
// windows releases suspended-mobile sockets well before Bun's 120s default.
|
||||
idleTimeout: 30,
|
||||
} as const;
|
||||
@@ -10,6 +10,7 @@ import * as HttpApiBuilder from "effect/unstable/httpapi/HttpApiBuilder";
|
||||
import * as BackgroundPolicy from "./background/BackgroundPolicy.ts";
|
||||
import * as HostPowerMonitor from "./background/HostPowerMonitor.ts";
|
||||
import * as ServerConfig from "./config.ts";
|
||||
import { bunWebSocketOptions } from "./httpServerOptions.ts";
|
||||
import {
|
||||
otlpTracesProxyRouteLayer,
|
||||
assetRouteLayer,
|
||||
@@ -185,26 +186,7 @@ const HttpServerLive = Layer.unwrap(
|
||||
port: config.port,
|
||||
hostname: config.host ?? "127.0.0.1",
|
||||
gracefulShutdownTimeout: HTTP_PREEMPTIVE_SHUTDOWN_GRACE_MS,
|
||||
websocket: {
|
||||
// Negotiate permessage-deflate with clients that offer it; clients
|
||||
// that don't still get uncompressed frames on their connection. A
|
||||
// dedicated compressor keeps a per-connection sliding window
|
||||
// (context takeover) so the compression dictionary is shared across
|
||||
// server-to-client frames. Decompression uses the shared
|
||||
// decompressor: uWebSockets' dedicated decompressor path can abort
|
||||
// connections (close 1006) on valid DEFLATE input — see
|
||||
// https://github.com/uNetworking/uWebSockets.js/issues/633.
|
||||
perMessageDeflate: {
|
||||
compress: "dedicated",
|
||||
decompress: "shared",
|
||||
},
|
||||
// Reap connections that stop sending within 30s instead of Bun's
|
||||
// 120s default. RPC clients ping every 5s, so a live client never
|
||||
// idles; a suspended mobile app stops pinging and its half-dead
|
||||
// socket (plus the server-side buffers feeding it) is released
|
||||
// four times sooner.
|
||||
idleTimeout: 30,
|
||||
},
|
||||
websocket: bunWebSocketOptions,
|
||||
});
|
||||
} else {
|
||||
const [NodeHttpServer, NodeHttp] = yield* Effect.all([
|
||||
|
||||
@@ -943,12 +943,10 @@ describe("EnvironmentSupervisor", () => {
|
||||
// and must not trigger an early retry.
|
||||
yield* harness.wake("network-path-changed");
|
||||
yield* harness.wake("network-path-changed");
|
||||
for (let attempt = 0; attempt < 20; attempt += 1) {
|
||||
yield* Effect.yieldNow;
|
||||
}
|
||||
yield* TestClock.adjust("2999 millis");
|
||||
expect(yield* Ref.get(harness.prepareCount)).toBe(1);
|
||||
expect((yield* SubscriptionRef.get(supervisor.state)).phase).toBe("backoff");
|
||||
}),
|
||||
}).pipe(Effect.provide(TestClock.layer())),
|
||||
);
|
||||
|
||||
it.effect("immediately replaces a mobile session after a long background resume", () =>
|
||||
|
||||
Reference in new issue
Block a user