fix(server): keep connections open 240 s; Bun's 10 s default cut slow Wayback lookups off

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Lucas WintherandClaude Opus 5.5 committed 2026-10-15 00:43:47 +02:00
1 parent 6f43ef0615
commit aea4a1a35c
4 files changed
+17 -3

No files matched your search

+1 -1
View File
@@ -21,7 +21,7 @@ export interface ServerEnv {
}
export const MAX_REDIRECTS = 5;
const UPSTREAM_TIMEOUT_MS = 30_000;
export const UPSTREAM_TIMEOUT_MS = 30_000;
/** Pages whose scripts may call our API besides our own (the userscript runs on mangabaka.org). */
const EXTRA_ORIGINS = new Set(["https://mangabaka.org"]);
+2 -2
View File
@@ -1,7 +1,7 @@
// Self-hosted entry: Bun.serve behind our reverse proxy (spec §4.10). Keep it thin.
import { join, resolve } from "node:path";
import { createApp } from "./app";
import { clientIp, readConfig } from "./config";
import { SERVER_IDLE_TIMEOUT_S, clientIp, readConfig } from "./config";
import { DirStorage } from "./storage-dir";
const config = readConfig(process.env);
@@ -31,7 +31,7 @@ const app = createApp({
clientIp: (req) => clientIp(req, config.trustProxy, server.requestIP(req)?.address),
});
server = Bun.serve({ port: config.port, hostname: config.hostname, fetch: app });
server = Bun.serve({ port: config.port, hostname: config.hostname, idleTimeout: SERVER_IDLE_TIMEOUT_S, fetch: app });
console.log(
`mangabaka-seeder on http://${server.hostname}:${server.port} · storage: ${
storage ? `${config.storageDir} (${storage.usedBytes()} of ${config.storageMaxBytes} bytes)` : "off"
+5
View File
@@ -15,6 +15,11 @@ export class ConfigError extends Error {
}
export const DEFAULT_STORAGE_MAX_BYTES = 1024 ** 3;
/**
* Seconds the Bun server keeps a quiet connection open. Its default (10 s) dropped slow Wayback lookups
* mid-request; this must outlast a proxied fetch plus a catbox upload. Bun's maximum is 255.
*/
export const SERVER_IDLE_TIMEOUT_S = 240;
export function readConfig(env: Record<string, string | undefined>): ServerConfig {
const publicUrl = parsePublicUrl(env.MBSEED_PUBLIC_URL);
+9
View File
@@ -67,3 +67,12 @@ describe("resolveAssetPath", () => {
expect(resolveAssetPath(path)).toBeNull();
});
});
test("the server keeps a connection open longer than its own slowest upstream work", async () => {
// Bun.serve's default idleTimeout (10 s) cut slow Wayback lookups off mid-request ("Failed to fetch").
const { SERVER_IDLE_TIMEOUT_S } = await import("../src/server/config");
const { UPSTREAM_TIMEOUT_MS } = await import("../src/server/app");
const { UPLOAD_TIMEOUT_MS } = await import("../src/core/hosting/host");
expect(SERVER_IDLE_TIMEOUT_S * 1000).toBeGreaterThan(UPSTREAM_TIMEOUT_MS + UPLOAD_TIMEOUT_MS);
expect(SERVER_IDLE_TIMEOUT_S).toBeLessThanOrEqual(255); // Bun's maximum
});