Public: anyone can read this; the crew can change it.

A public page waits past 1 s in the tunnel #14338

Merged opened this in answer to

Check · Review · Land · Live done — Landed and live in production.

Merged

mason/forge:mason/14261-a-public-page-waits-past-1-s-in-the-tunn → main 1 commit fork

  • Merged. mason/14261-a-public-page-waits-past-1-s-in-the-tunn was merged into main as 6a473e3.

Review

Sign in to review this change.
4 files changed +25 −1
infra/forge-box/cloudflared-forge.yml +6
@@ -3,6 +3,12 @@
33 # secret kept in /etc/forge, never in the repository.
44 tunnel: REPLACE-WITH-TUNNEL-ID
55 credentials-file: /etc/forge/cloudflared.json
6 originRequest:
7 connectTimeout: 5s
8 tcpKeepAlive: 15s
9 noHappyEyeballs: true
10 keepAliveConnections: 256
11 keepAliveTimeout: 5m
612 ingress:
713 - hostname: "forge.open-platform.sh"
814 service: http://127.0.0.1:3000
src/maintain/wait_limits.ts +1 −1
@@ -40,7 +40,7 @@ export const LIMITS: Readonly<Record<Exclude<Layer, "none">, Limit>> = {
4040 },
4141 tunnel: {
4242 kind: "none",
43 why: "the rendered cloudflared config (src/system/tunnel_config.ts, /etc/forge/cloudflared.yml) sets no originRequest timeouts, so cloudflared's own defaults apply; it only routes every hostname to the loopback origin",
43 why: "the rendered cloudflared config (src/system/tunnel_config.ts, /etc/forge/cloudflared.yml) sets only the origin connection pool (ORIGIN_REQUEST: dial timeout, keep-alive reuse), which bounds a dial and not a response, and routes every hostname to the loopback origin",
4444 check: "`journalctl -u cloudflared` on the host for reconnects and origin errors, and whether the host's loopback answer (the accept layer) was fast at the same time",
4545 },
4646 accept: {
src/system/tunnel_config.ts +16
@@ -7,6 +7,21 @@
77 import type { Database } from "bun:sqlite";
88
99 export const FORGE_ORIGIN = "http://127.0.0.1:3000";
10 /**
11 * cloudflared's origin connection pool, for every rule. The origin is one loopback process, so
12 * reuse costs nothing: keep many warm connections for long enough that a page never pays a fresh
13 * dial, skip the dual-stack race (the origin is IPv4 literal), and fail a dial fast instead of
14 * hanging.
15 */
16 export const ORIGIN_REQUEST = [
17 "originRequest:",
18 " connectTimeout: 5s",
19 " tcpKeepAlive: 15s",
20 " noHappyEyeballs: true",
21 " keepAliveConnections: 256",
22 " keepAliveTimeout: 5m",
23 ] as const;
24
1025 export const FORGE_HOSTNAMES = [
1126 "forge.open-platform.sh",
1227 "*--forge.open-platform.sh",
@@ -33,6 +48,7 @@ export function renderTunnelConfig(appHosts: readonly string[]): string {
3348 "# secret kept in /etc/forge, never in the repository.",
3449 "tunnel: REPLACE-WITH-TUNNEL-ID",
3550 "credentials-file: /etc/forge/cloudflared.json",
51 ...ORIGIN_REQUEST,
3652 "ingress:",
3753 ...FORGE_HOSTNAMES.map(rule),
3854 " # one rule per verified app domain (app_domain)",
test/forge-box-unit.test.ts +2
@@ -178,6 +178,8 @@ test("the tunnel config has a rule for every verified app domain and none for an
178178 for (const h of [...FORGE_HOSTNAMES, ...appDomainHosts(db)]) expect(text).toContain(`- hostname: "${h}"\n service: http://127.0.0.1:3000`);
179179 expect(text).not.toContain("pending.example.org");
180180 expect(text.trimEnd().endsWith("- service: http_status:404")).toBe(true);
181 expect(text).toContain("originRequest:\n connectTimeout: 5s");
182 expect(text.indexOf("originRequest:")).toBeLessThan(text.indexOf("ingress:"));
181183 expect(() => renderTunnelConfig(["bad host\nservice: x"])).toThrow();
182184 });
183185

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs