golang/go · error · Error
total length of command line and environment variables excee
Error message
total length of command line and environment variables exceeds limit
What it means
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.
Source
Thrown at lib/wasm/wasm_exec.js:545
const keys = Object.keys(this.env).sort();
keys.forEach((key) => {
argvPtrs.push(strPtr(`${key}=${this.env[key]}`));
});
argvPtrs.push(0);
const argv = offset;
argvPtrs.forEach((ptr) => {
this.mem.setUint32(offset, ptr, true);
this.mem.setUint32(offset + 4, 0, true);
offset += 8;
});
// The linker guarantees global data starts from at least wasmMinDataAddr.
// Keep in sync with cmd/link/internal/ld/data.go:wasmMinDataAddr.
const wasmMinDataAddr = 4096 + 8192;
if (offset >= wasmMinDataAddr) {
throw new Error("total length of command line and environment variables exceeds limit");
}
this._inst.exports.run(argc, argv);
if (this.exited) {
this._resolveExitPromise();
}
await this._exitPromise;
}
_resume() {
if (this.exited) {
throw new Error("Go program has already exited");
}
this._inst.exports.resume();
if (this.exited) {
this._resolveExitPromise();
}
}View on GitHub (pinned to b6b368adc5)
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).
Example fix
// before go.env = process.env; // forwards 200+ vars, throws: total length ... exceeds limit await go.run(instance); // after const needed = ['NODE_ENV','API_TOKEN','REGION']; go.env = Object.fromEntries(needed.map(k => [k, process.env[k]]).filter(([,v]) => v !== undefined)); await go.run(instance);
Defensive patterns
Strategy: validation
Validate before calling
const MAX = 4096 + 8192; // wasmMinDataAddr
const total = [...go.argv, ...Object.entries(go.env).map(([k,v]) => `${k}=${v}`)].join('\0').length;
if (total >= MAX) {
throw new Error(`argv+env too large (${total} >= ${MAX}); reduce environment variables`);
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- globalThis.crypto is not available, polyfill required (crypt
- globalThis.performance is not available, polyfill required (
- globalThis.TextEncoder is not available, polyfill required
- globalThis.TextDecoder is not available, polyfill required
- Go.run: WebAssembly.Instance expected
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/11b02a7eddf7ad33.
Report an issue: GitHub.