From 1f0c7bd0996164d9fbba1333a115be0444d872ba Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Thu, 19 Mar 2026 11:50:10 -0700 Subject: [PATCH] Remove try-catch from perfToggle and fix perf timing flag read Let errors propagate to the caller instead of catching locally, simplify the request body construction, and snapshot perf.timing before the fetch to avoid a TOCTOU race. --- src/cli/commands/perf.ts | 28 ++++++++++++---------------- src/server/proxy.ts | 9 +++++---- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/cli/commands/perf.ts b/src/cli/commands/perf.ts index ae6d99a..58addb8 100644 --- a/src/cli/commands/perf.ts +++ b/src/cli/commands/perf.ts @@ -1,21 +1,17 @@ import color from 'ansis' -import { get, handleError, post } from '../http' +import { get, post } from '../http' export async function perfToggle(onOff?: string) { - try { - if (onOff && !['on', 'off', 'status'].includes(onOff)) { - console.error('Usage: toes perf [on|off|status]') - process.exit(1) - } - const res = onOff === 'status' - ? await get<{ perfTiming: boolean }>('/api/system/perf') - : await post<{ perfTiming: boolean }>('/api/system/perf', - onOff === 'on' ? { on: true } : onOff === 'off' ? { on: false } : {}) - if (res) { - const label = res.perfTiming ? color.green('on') : color.red('off') - console.log(`Perf timing ${onOff === 'status' ? 'is ' : ''}${label}`) - } - } catch (error) { - handleError(error) + if (onOff && !['on', 'off', 'status'].includes(onOff)) { + console.error('Usage: toes perf [on|off|status]') + process.exit(1) + } + const body = onOff && onOff !== 'status' ? { on: onOff === 'on' } : {} + const res = onOff === 'status' + ? await get<{ perfTiming: boolean }>('/api/system/perf') + : await post<{ perfTiming: boolean }>('/api/system/perf', body) + if (res) { + const label = res.perfTiming ? color.green('on') : color.red('off') + console.log(`Perf timing ${onOff === 'status' ? 'is ' : ''}${label}`) } } diff --git a/src/server/proxy.ts b/src/server/proxy.ts index 09d292e..9733480 100644 --- a/src/server/proxy.ts +++ b/src/server/proxy.ts @@ -1,10 +1,10 @@ import type { Server, ServerWebSocket } from 'bun' import { getAppBySubdomain } from '$apps' -export type { WsData } - export const perf = { timing: false } +export type { WsData } + const pendingMessages = new Map, (string | ArrayBuffer | Uint8Array)[]>() const upstreams = new Map, WebSocket>() @@ -55,14 +55,15 @@ export async function proxySubdomain(subdomain: string, req: Request): Promise