{"record":{"id":"11b02a7eddf7ad33","repo":"golang/go","slug":"total-length-of-command-line-and-environment-varia","errorCode":null,"errorMessage":"total length of command line and environment variables exceeds limit","messagePattern":"total length of command line and environment variables exceeds limit","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/wasm/wasm_exec.js","lineNumber":545,"sourceCode":"\n\t\t\tconst keys = Object.keys(this.env).sort();\n\t\t\tkeys.forEach((key) => {\n\t\t\t\targvPtrs.push(strPtr(`${key}=${this.env[key]}`));\n\t\t\t});\n\t\t\targvPtrs.push(0);\n\n\t\t\tconst argv = offset;\n\t\t\targvPtrs.forEach((ptr) => {\n\t\t\t\tthis.mem.setUint32(offset, ptr, true);\n\t\t\t\tthis.mem.setUint32(offset + 4, 0, true);\n\t\t\t\toffset += 8;\n\t\t\t});\n\n\t\t\t// The linker guarantees global data starts from at least wasmMinDataAddr.\n\t\t\t// Keep in sync with cmd/link/internal/ld/data.go:wasmMinDataAddr.\n\t\t\tconst wasmMinDataAddr = 4096 + 8192;\n\t\t\tif (offset >= wasmMinDataAddr) {\n\t\t\t\tthrow new Error(\"total length of command line and environment variables exceeds limit\");\n\t\t\t}\n\n\t\t\tthis._inst.exports.run(argc, argv);\n\t\t\tif (this.exited) {\n\t\t\t\tthis._resolveExitPromise();\n\t\t\t}\n\t\t\tawait this._exitPromise;\n\t\t}\n\n\t\t_resume() {\n\t\t\tif (this.exited) {\n\t\t\t\tthrow new Error(\"Go program has already exited\");\n\t\t\t}\n\t\t\tthis._inst.exports.resume();\n\t\t\tif (this.exited) {\n\t\t\t\tthis._resolveExitPromise();\n\t\t\t}\n\t\t}","sourceCodeStart":527,"sourceCodeEnd":563,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/lib/wasm/wasm_exec.js#L527-L563","documentation":"Thrown by Go.run in wasm_exec.js after laying out argv and env strings in wasm linear memory. The Go linker reserves the first 4096+8192 bytes (wasmMinDataAddr) for global data; if argv+env pointers push the offset past that boundary, the runtime would overwrite globals, so it refuses to start. It is a hard limit on the combined size of command-line arguments and environment variables passed to the Go wasm program.","triggerScenarios":"Setting many environment variables on the Go instance (go.env = {...}) such that their keys+values total more than ~12KB; passing very long argv strings (go.argv = [...]); a combination of both crossing the wasmMinDataAddr = 12288 byte threshold.","commonSituations":"Forwarding an entire process.env (often huge on CI systems) into go.env; embedding credentials/tokens as many env vars; passing large inline config via argv; misconfigured build that injects hundreds of env vars for tracing/observability.","solutions":["Reduce the env vars passed to the Go wasm program: forward only the keys the program actually needs, e.g. go.env = { GOOS: process.env.GOOS }; instead of go.env = process.env;","Move large configuration out of env/argv and into a file read at runtime, or fetch from a URL.","Trim individual values: shorten tokens, use file paths instead of inline JSON in argv.","If the limit is genuinely too low, rebuild the Go program with a linker configuration that raises wasmMinDataAddr (advanced; requires editing cmd/link/internal/ld/data.go)."],"exampleFix":"// before\ngo.env = process.env; // forwards 200+ vars, throws: total length ... exceeds limit\nawait go.run(instance);\n\n// after\nconst needed = ['NODE_ENV','API_TOKEN','REGION'];\ngo.env = Object.fromEntries(needed.map(k => [k, process.env[k]]).filter(([,v]) => v !== undefined));\nawait go.run(instance);","handlingStrategy":"validation","validationCode":"const MAX = 4096 + 8192; // wasmMinDataAddr\nconst total = [...go.argv, ...Object.entries(go.env).map(([k,v]) => `${k}=${v}`)].join('\\0').length;\nif (total >= MAX) {\n  throw new Error(`argv+env too large (${total} >= ${MAX}); reduce environment variables`);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never assign go.env = process.env wholesale on CI — process.env can be huge.","Maintain an allowlist of env keys the Go program actually needs.","Push large configuration into files or runtime fetches rather than env/argv."],"tags":["wasm","go","argv","environment-variables","memory-limit","configuration"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}