From 789a582fd5b31c01667b0fa49fc5212f41ace5b0 Mon Sep 17 00:00:00 2001 From: Sharad-Patel1 Date: Mon, 16 Nov 2026 01:23:52 +0000 Subject: [PATCH] fix(server): a host GODEBUG with a removed Go setting no longer breaks Go CLIs Co-Authored-By: Claude Opus 5.5 --- apps/server/src/bin.ts | 4 ++++ apps/server/src/goDebug.test.ts | 20 ++++++++++++++++++++ apps/server/src/goDebug.ts | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 apps/server/src/goDebug.test.ts create mode 100644 apps/server/src/goDebug.ts diff --git a/apps/server/src/bin.ts b/apps/server/src/bin.ts index 7b980e01b5..a1d1fa776d 100644 --- a/apps/server/src/bin.ts +++ b/apps/server/src/bin.ts @@ -4,6 +4,7 @@ import * as NodeSea from "node:sea"; import * as NodeURL from "node:url"; import { isEntrypoint } from "./entrypoint.ts"; +import { dropRemovedGoDebugSettings } from "./goDebug.ts"; // Loads the CLI outside the launcher's module graph. Packaged builds embed it as a raw asset. async function loadCliMain(): Promise { @@ -45,6 +46,9 @@ if ( process.stdout.on("error", ignoreOutputError); process.stderr.on("error", ignoreOutputError); + // Before anything spawns, since child processes inherit process.env by default. + dropRemovedGoDebugSettings(process.env); + // The launcher owns shutdown until its child exits, so it bypasses the Effect CLI runtime. // A service unit passes nothing, or on Windows the launcher's own flags; help and anything // else go through the full CLI. diff --git a/apps/server/src/goDebug.test.ts b/apps/server/src/goDebug.test.ts new file mode 100644 index 0000000000..a7bdb86bd7 --- /dev/null +++ b/apps/server/src/goDebug.test.ts @@ -0,0 +1,20 @@ +import { assert, it } from "vite-plus/test"; + +import { dropRemovedGoDebugSettings } from "./goDebug.ts"; + +const KEPT_BY_GO = + "tlskyber=1,tlskyber=00,tlskyber=0 ,tlskyber=0=1,tlskyber,TLSKYBER=0,http2client=0"; + +it.each([ + ["tlskyber=0", undefined], + ["http2client=0,tlskyber=0", "http2client=0"], + ["asynctimerchan=2,tlsrsakex=1,x509sha1=1", undefined], + // Go aborts on a field at its old value even when a later field overrides it. + ["tlskyber=0,tlskyber=1", "tlskyber=1"], + // Go matches keys and values exactly, splits on the first "=", and skips fields without one. + [KEPT_BY_GO, KEPT_BY_GO], +])("GODEBUG=%s becomes %s", (godebug, expected) => { + const env: NodeJS.ProcessEnv = { GODEBUG: godebug }; + dropRemovedGoDebugSettings(env); + assert.deepStrictEqual(env, expected === undefined ? {} : { GODEBUG: expected }); +}); diff --git a/apps/server/src/goDebug.ts b/apps/server/src/goDebug.ts new file mode 100644 index 0000000000..d6cd47d0a4 --- /dev/null +++ b/apps/server/src/goDebug.ts @@ -0,0 +1,33 @@ +// Go 1.27+ binaries abort at startup when GODEBUG sets a removed setting to its old value +// (go.dev/issue/76163), as UGOS's `GODEBUG=tlskyber=0` profile does. Mirrors `Removed` in Go's +// src/internal/godebugs/table.go. +const REMOVED_SETTING_OLD_VALUES: ReadonlyMap> = new Map([ + ["x509sha1", ["1"]], + ["tlskyber", ["0"]], + ["gotypesalias", ["0"]], + ["tlsunsafeekm", ["1"]], + ["tlsrsakex", ["1"]], + ["tls3des", ["1"]], + ["tls10server", ["1"]], + ["x509keypairleaf", ["0"]], + ["asynctimerchan", ["1", "2"]], +]); + +function isRemovedSettingAtOldValue(field: string) { + const separator = field.indexOf("="); + if (separator < 0) return false; + const oldValues = REMOVED_SETTING_OLD_VALUES.get(field.slice(0, separator)); + return oldValues?.includes(field.slice(separator + 1)) ?? false; +} + +export function dropRemovedGoDebugSettings(env: NodeJS.ProcessEnv): void { + const fields = env.GODEBUG?.split(",") ?? []; + const kept = fields.filter((field) => !isRemovedSettingAtOldValue(field)); + if (kept.length === fields.length) return; + const value = kept.join(","); + if (value === "") { + delete env.GODEBUG; + } else { + env.GODEBUG = value; + } +}