skip to content

An image-metadata Cloudflare Worker that parses large JSON uploads starts returning Error 1102 under load; how do you tell whether CPU or memory is the cause, and fix it?

level: seniorimportance: should knowfreq 50%

answer

  1. one error code, two limits
  2. invocation outcome names the limit
  3. memory is per isolate, shared
  4. buffering versus a size cap

basics

~20 s

Error 1102, Worker exceeded resource limits, covers both the CPU time limit and the 128 MB per-isolate memory limit; the outcome exceededCpu or exceededMemory says which. Cut work or raise limits.cpu_ms for CPU; stop buffering large bodies for memory.

solid answer

~40 s

Error 1102 (`Worker exceeded resource limits`) is returned for both a CPU overrun and a memory overrun, so the first step is the invocation outcome: Workers Logs, `wrangler tail` and Logpush record `exceededCpu` or `exceededMemory`, and the dashboard's Invocation Statuses split `Exceeded CPU Time Limits` from `Exceeded Memory`. For CPU, compare the CPU time in the invocation logs with `limits.cpu_ms`; on Workers Paid raise it up to 300,000 ms, or profile and cut the parsing work. The phrase *under load* points at memory: the 128 MB limit applies per isolate, and one isolate serves many concurrent requests, so ten buffered 15 MB uploads plus their parsed objects can exceed it although each fits alone. Cap the accepted body size, avoid holding whole payloads in memory, and keep large data in R2.

code

javascript · 13 lines
javascript
const MAX_BYTES = 5 * 1024 * 1024; // refuse bodies the Worker should not buffer

export default {
  async fetch(request) {
    const declared = Number(request.headers.get("content-length"));
    if (!Number.isFinite(declared) || declared <= 0 || declared > MAX_BYTES) {
      return new Response("Send a JSON body of at most 5 MB", { status: 413 });
    }
    const payload = await request.json();
    const images = Array.isArray(payload.images) ? payload.images : [];
    return Response.json({ count: images.length });
  },
};

go deeper

for a junior

Recall that Error 1102 means the Worker exceeded resource limits, either CPU time or the 128 MB memory limit, and is different from Error 1101 for an uncaught exception.

for a middle

Explain how the invocation outcomes exceededCpu and exceededMemory separate the two causes, and which setting, limits.cpu_ms, exists for only one of them.

for a senior

Walk the diagnosis: outcomes in Workers Logs, CPU time against cpu_ms, memory shared across concurrent requests on an isolate, then body caps or offloading as the fix, verified against a deployed Worker.

for a principal

Decide which workloads belong in an isolate at all: large-payload processing may justify a body-size policy, R2-first designs, or another compute product rather than ever-higher CPU limits.

## What Error 1102 means Error 1102 is the error page Cloudflare returns when a Worker invocation is stopped for exceeding a runtime resource limit. Its message is `Worker exceeded resource limits`, and the Workers documentation attaches it to two different limits: - the **CPU time limit**: 10 ms per request on Workers Free, 30 seconds by default on Workers Paid, configurable with `limits.cpu_ms` up to 300,000 ms; - the **memory limit**: 128 MB **per isolate**, covering the JavaScript heap and WebAssembly allocations. Error 1102 is not an exception in your code; an uncaught exception is Error 1101. So the code alone does not tell you which limit you hit. ## Telling CPU from memory | Signal | CPU overrun | Memory overrun | |---|---|---| | Invocation outcome in Workers Logs, Tail Workers, Logpush | `exceededCpu` | `exceededMemory` | | Dashboard, Metrics > Errors > Invocation Statuses | `Exceeded CPU Time Limits` | `Exceeded Memory` | | Related runtime error | none | `Memory limit would be exceeded before EOF` when buffering a body | | Scales with | work done per request | everything held at once by all requests on the isolate | The aggregate GraphQL analytics fold both into the `exceededResources` status, so use per-invocation outcomes rather than that total. Each invocation log also shows CPU time and wall time, which tells you how close the CPU-bound requests run to `cpu_ms`. ## Why load makes memory the usual suspect The CPU limit is counted per invocation, so a payload that parses within budget alone still parses within budget beside other requests. Memory is different. One isolate serves many requests concurrently, and the 128 MB limit is per isolate, not per invocation. In the image-metadata Worker, every in-flight upload holds its buffered text and then a parsed object graph that is larger than the text. A handful of concurrent multi-megabyte uploads fits nowhere near 128 MB, even though any single one does. When the isolate exceeds the limit, the runtime lets in-flight requests complete and creates a new isolate for subsequent requests; during extremely high load it may also cancel some incoming requests. ## Reading the evidence in order A short sequence keeps the diagnosis honest: 1. Filter the failing invocations in Workers Logs (or a `wrangler tail` session) and count outcomes: all `exceededCpu`, all `exceededMemory`, or a mix. 2. For CPU, put the CPU time of successful requests next to `limits.cpu_ms`. If successful large uploads already run close to the limit, the failures are the tail of the same distribution. 3. For memory, line the errors up with concurrency and payload size. Errors that cluster at traffic peaks while single large requests succeed point at what many requests hold at the same moment, not at any one request. 4. Only then choose the fix, because the CPU and memory remedies do not overlap. ## Fixing a CPU overrun 1. Read the CPU time on the failing invocations and compare it with the configured `limits.cpu_ms`. 2. On Workers Paid, raise `cpu_ms` if the work is legitimate; the ceiling is 300,000 ms (5 minutes). 3. Profile with Chrome DevTools to find the hot code, and cut work: skip fields you never use, avoid re-parsing, precompute. 4. Move heavy, non-interactive work off the request path, processing it in smaller chunks or a background system. ## Fixing a memory overrun 1. **Cap the body size** before reading it, and reject oversize uploads with `413`. 2. **Stop buffering**: stream bodies through rather than calling `await request.text()` on huge inputs. 3. **Keep large data out of the isolate**: store uploads in R2 and process them in parts. 4. **Profile memory** with DevTools memory profiling to find leaks and oversized allocations, including module-scope caches that grow without bound. 5. Raising `limits.cpu_ms` does nothing here; no Wrangler configuration key raises the 128 MB. ## What a local run will not show Under `wrangler dev`, the `limits` settings are not enforced, and the local runtime does not hold an isolate to 128 MB either, so a load test against a local server can pass while production returns 1102. Reproduce with realistic payload sizes and concurrency against a deployed version, and rely on the outcomes in Workers Logs. A Worker that only rarely runs slightly over its CPU limit may also pass, because each isolate allows some built-in flexibility for infrequent overruns; consistent overruns are terminated.

  • Why can a Worker run slightly over its CPU limit and still succeed sometimes?
    Each isolate has some built-in flexibility for a Worker that exceeds the configured CPU limit only infrequently. If the Worker starts hitting the limit consistently, its invocations are terminated with Error 1102. So intermittent success near the limit is a warning, not proof the Worker fits.
  • When is raising limits.cpu_ms the wrong fix for Error 1102?
    When the outcome is `exceededMemory`: CPU settings do not change the 128 MB per-isolate memory limit. It is also the wrong first move when the CPU cost comes from avoidable work such as re-parsing, or when a user is waiting on the response; profile and cut the work, or move it off the request path.

  • Error 1102 always means the CPU limit, so raising limits.cpu_ms fixes it.
  • Each request gets its own 128 MB, so concurrency cannot cause memory errors.
  • Raising limits.cpu_ms also gives the Worker more memory.
  • Error 1102 means the Worker threw an uncaught JavaScript exception.
  • A load test against wrangler dev proves production will not return 1102.

Assumes Workers limits as of 2026-10-10: 128 MB per isolate, and a Paid CPU limit of 30 seconds by default, raisable to 5 minutes since March 2025.