denoland/deno · error · TypeError

ERR_HTTP2_ORIGIN_LENGTH

ERR_HTTP2_ORIGIN_LENGTH

Error message

HTTP/2 ORIGIN frames are limited to 16382 bytes

What it means

origin() concatenates all validated origins (each followed by a NUL byte) into one frame payload, and the sum of the origin string lengths (len, not counting the separators) must stay within kMaxALTSVC = 16382 bytes. Exceeding it throws ERR_HTTP2_ORIGIN_LENGTH, reusing the same 16-bit length budget as ALTSVC, because one frame cannot carry the list.

Source

Thrown at ext/node/polyfills/http2.ts:4664

    const count = origins.length;
    for (let i = 0; i < count; i++) {
      let origin = origins[i];
      if (typeof origin === "string") {
        origin = getURLOrigin(origin);
      } else if (origin != null && typeof origin === "object") {
        origin = origin.origin;
      }
      validateString(origin, "origin");
      if (origin === "null") {
        throw new ERR_HTTP2_INVALID_ORIGIN();
      }

      arr += `${origin}\0`;
      len += origin.length;
    }

    if (len > kMaxALTSVC) {
      throw new ERR_HTTP2_ORIGIN_LENGTH();
    }

    this[kHandle].origin(arr, count);
  }
}

// ClientHttp2Session instances have to wait for the socket to connect after
// they have been created. Various operations such as request() may be used,
// but the actual protocol communication will only occur after the socket
// has been connected.
class ClientHttp2Session extends Http2Session {
  constructor(options, socket) {
    initCallbacks();
    super(NGHTTP2_SESSION_CLIENT, options, socket);
    this[kPendingRequestCalls] = null;
  }

  // Submits a new HTTP2 request to the connected peer. Returns the

View on GitHub (pinned to 9ad36f7a2c)

Solutions

  1. Split the origins across multiple session.origin() calls — each call emits its own frame
  2. Reduce the list to origins the client will actually coalesce over this connection
  3. Chunk the list: for (let i = 0; i < origins.length; i += 500) session.origin(...origins.slice(i, i + 500))

Example fix

// before
session.origin(...allOrigins); // combined length > 16382

// after
const CHUNK = 500;
for (let i = 0; i < allOrigins.length; i += CHUNK) {
  session.origin(...allOrigins.slice(i, i + CHUNK));
}
Defensive patterns

Strategy: validation

Validate before calling

const CHUNK = 500;
for (let i = 0; i < origins.length; i += CHUNK) {
  session.origin(...origins.slice(i, i + CHUNK));
}

Prevention

When it happens

Trigger: Passing hundreds or thousands of origins in a single session.origin(...origins) call such that the combined origin strings exceed 16382 characters.

Common situations: Wildcard-multi-tenant servers enumerating every tenant hostname in one call; origin lists generated from DNS zone files; a growing origin list that slowly approaches the limit across deployments.

Related errors


AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20). Data as JSON: /api/errors/614941790b6977c7. Report an issue: GitHub.