denoland/deno · error · TypeError
ERR_HTTP2_ALTSVC_LENGTH
ERR_HTTP2_ALTSVC_LENGTH
Error message
HTTP/2 ALTSVC frames are limited to 16382 bytes
What it means
An ALTSVC frame's payload is capped at kMaxALTSVC = 2**14 - 2 = 16382 bytes. altsvc() throws ERR_HTTP2_ALTSVC_LENGTH when alt.length plus origin.length (when an origin string is present) exceeds that budget, because the frame cannot carry more without violating the protocol's 16-bit length field.
Source
Thrown at ext/node/polyfills/http2.ts:4628
"number",
"URL",
"object",
], originOrStream);
} else if (origin === "null" || origin.length === 0) {
throw new ERR_HTTP2_ALTSVC_INVALID_ORIGIN();
}
}
validateString(alt, "alt");
if (!kQuotedString.test(alt)) {
throw new ERR_INVALID_CHAR("alt");
}
// Max length permitted for ALTSVC
if (
(alt.length + (origin !== undefined ? origin.length : 0)) > kMaxALTSVC
) {
throw new ERR_HTTP2_ALTSVC_LENGTH();
}
this[kHandle].altsvc(stream, origin || "", alt);
}
// Submits an origin frame to be sent.
origin(...origins) {
if (this.destroyed) {
throw new ERR_HTTP2_INVALID_SESSION();
}
if (origins.length === 0) {
return;
}
let arr = "";
let len = 0;
const count = origins.length;View on GitHub (pinned to 9ad36f7a2c)
Solutions
- Split into multiple altsvc() calls — each call is its own frame, so advertise one (or few) alternates per call
- Trim the origin and alt to what the peer can actually use (typically 'h2=":port"', ~12 bytes)
- Cap config-driven alt values at a sane length (e.g. 256 bytes) before submission
Example fix
// before
const alt = endpoints.map((e) => `h2="${e.host}:${e.port}"`).join(',');
session.altsvc(alt, origin); // can exceed 16382
// after
for (const e of endpoints) session.altsvc(`h2="${e.host}:${e.port}"`, origin); Defensive patterns
Strategy: validation
Validate before calling
const originLen = typeof origin === 'string' ? origin.length : 0;
if (alt.length + originLen > 16382) {
throw new RangeError('alt + origin exceeds the ALTSVC frame limit of 16382 bytes');
}
session.altsvc(alt, origin); Prevention
- One alternate per altsvc() call — each call is a separate frame
- Cap config-supplied alt values (256 bytes is generous; real values are ~10-30)
- The budget counts origin.length too when a string origin is present
When it happens
Trigger: A single altsvc call whose alt value and origin together exceed 16382 characters — e.g. advertising many protocols/hosts in one alt string built by concatenation.
Common situations: Generating the alt value from a large service catalog or long list of alternative endpoints; unbounded user-supplied alt-svc config; a loop that appends entries to one alt string instead of issuing one altsvc() per entry.
Related errors
- ERR_HTTP2_ALTSVC_INVALID_ORIGIN
- ERR_INVALID_CHAR
- ERR_HTTP2_ORIGIN_LENGTH
- ERR_INVALID_URL
- ERR_HTTP2_NO_SOCKET_MANIPULATION
AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20).
Data as JSON: /api/errors/842059557efb5bb7.
Report an issue: GitHub.