cloudflare / cloudflare/workers-sdk

TypeError: memory limit has been exceeded with inline data: URL

Open
#10,814 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
4.5k
Forks
1.5k
Avg merge
3d 8h
Merged PRs (30d)
186

Description

### What versions & operating system are you using?

This is a local reproduction of a bug we encounter in _production Cloudflare workers_.

The test environment has failed on many versions back to at least `3.82`, currently tests are against `wrangler@4.40.2`.

### Please provide a link to a minimal reproduction

https://github.com/agjohnson/wrangler-large-data-url

### Describe the Bug

This was originally reported against workerd:

- https://github.com/cloudflare/workerd/issues/2998

When serving an HTML file with a large (>10MB) inline `data:` URL resource, even a basic worker will halt the response and respond with:

```TypeError: Parser error: The memory limit has been exceeded.```

This bug is not related to _response size_ exclusively:

- If I send a 10MB file as `text/plain`, the file will send through the worker
- If I generate a 10MB HTML file with `/dev/random`, the file will send through the worker
- If I send HTML with an inline `data:` URL, the response truncates at the byte in the HTML file that an element with a data URL starts.

Also of note:

- There is no rewriter configured. The worker is only fetching from the origin and immediately serving the file: https://github.com/agjohnson/wrangler-large-data-url/blob/main/wrangler/index.js
- This is _not limited to the dev server_. This is a bug we've noticed for years on production Cloudflare workers.

### Please provide any relevant error logs

Logs are from my reproduction repo

```
wrangler-1 |
wrangler-1 | ⛅️ wrangler 4.40.2
wrangler-1 | ───────────────────
wrangler-1 | ⎔ Starting local server...
wrangler-1 | ⎔ Reloading local server...
wrangler-1 | [wrangler:info] Ready on http://0.0.0.0:8787
wrangler-1 | [wrangler:info] - http://127.0.0.1:8787
wrangler-1 | [wrangler:info] - http://172.19.0.3:8787
tests-1 | % Total % Received % Xferd Average Speed Time Time Time Current
tests-1 | Dload Upload Total Spent Left Speed
fileserver-1 | 172.19.0.3 - - [29/Sep/2025 23:20:10] "GET /10mb.html HTTP/1.1" 200 -
wrangler-1 | [wrangler:info] GET / 200 OK (13ms)
100 25 0 25 0 0 32 0 --:--:-- --:--:-- --:--:-- 32
tests-1 | % Total % Received % Xferd Average Speed Time Time Time Current
tests-1 | Dload Upload Total Spent Left Speed
```

Note: the output from `curl` here shows that it only downloaded `25` bytes, not 10MB+. The 25th byte in the HTML file is where the `img` tag with the data URL starts.

The next curl call will raise the exception instead of returning a truncated response:

```
fileserver-1 | 172.19.0.3 - - [29/Sep/2025 23:20:11] "GET /10mb.html HTTP/1.1" 200 -
wrangler-1 | ✘ [ERROR] Uncaught exception: workerd/api/html-rewriter.c++:100: failed: remote.jsg.TypeError: Parser error: The memory limit has been exceeded.
wrangler-1 |
wrangler-1 | stack: /usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@2ca1ab7 /usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@2c9e8c2 /usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@2b3dd90 /usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@2c99da0 /usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@2b33490 /usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@2b3414d /usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@4b9ca7f /usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@28b5910 /usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@28b5ee0 /usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@28b7370 /usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@28b7f10 /usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@2e440a5 /usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@1e1f6a0 /usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@3301cf0 /usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@4b9ca7f /usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@3300740 /usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@1e2e3f0 /usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@2b33780 /usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@2b33c5d /usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@4b9ca7f /usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@28b7640 /usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@28b7f10 /usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@1e1f6a0 /usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@3300740 /usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@1e2e3f0 /usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@2b33780 /usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@2b33c5d /usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@4b9ca7f /usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@4b9cf43 /usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@28b77c1 /usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@4b9ca7f /usr/local/lib/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@4b9e41b
wrangler-1 |
wrangler-1 |
wrangler-1 | [wrangler:info] GET / 200 OK (7ms)
100 25 0 25 0 0 89 0 --:--:-- --:--:-- --:--:-- 90
fileserver-1 | ----------------------------------------
fileserver-1 | Exception occurred during processing of request from ('172.19.0.3', 47620)
fileserver-1 | Traceback (most recent call last):
fileserver-1 | File "/usr/lib/python3.11/socketserver.py", line 691, in process_request_thread
fileserver-1 | self.finish_request(request, client_address)
fileserver-1 | File "/usr/lib/python3.11/http/server.py", line 1310, in finish_request
fileserver-1 | self.RequestHandlerClass(request, client_address, self,
fileserver-1 | File "/usr/lib/python3.11/http/server.py", line 671, in __init__
fileserver-1 | super().__init__(*args, **kwargs)
fileserver-1 | File "/usr/lib/python3.11/socketserver.py", line 755, in __init__
fileserver-1 | self.handle()
fileserver-1 | File "/usr/lib/python3.11/http/server.py", line 436, in handle
fileserver-1 | self.handle_one_request()
fileserver-1 | File "/usr/lib/python3.11/http/server.py", line 424, in handle_one_request
fileserver-1 | method()
fileserver-1 | File "/usr/lib/python3.11/http/server.py", line 678, in do_GET
fileserver-1 | self.copyfile(f, self.wfile)
fileserver-1 | File "/usr/lib/python3.11/http/server.py", line 877, in copyfile
fileserver-1 | shutil.copyfileobj(source, outputfile)
fileserver-1 | File "/usr/lib/python3.11/shutil.py", line 200, in copyfileobj
fileserver-1 | fdst_write(buf)
fileserver-1 | File "/usr/lib/python3.11/socketserver.py", line 834, in write
fileserver-1 | self._sock.sendall(b)
fileserver-1 | ConnectionResetError: [Errno 104] Connection reset by peer
fileserver-1 | ----------------------------------------
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.