cloudflare / cloudflare/workerd
2M POST error: "RangeError: Responses may only be constructed with status codes in the range 200 to 599, inclusive."
- Dominant language
- C++
- Stars
- 8.7k
- Forks
- 739
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 174
Description
## What happened?
wrangler is giving an unexpected 503 response without even reaching the upstream application when the POST request has a 2M payload.
It has no problems if the payload is only 200K.
## What's expected?
2M shouldn't be large and it should be forwarded like the one with 200K. It should be streaming as well because the body is never read from the worker code.
## Details about the request and response
We're using wrangler to run [HTTP Router](https://gitlab.com/gitlab-org/cells/http-router), and we notice if we make a POST request with 2M payload, workderd seems to have problems.
The response looks like this:
```
< HTTP/1.1 503 Service Unavailable
< Content-Length: 224
< Content-Type: text/plain;charset=UTF-8
< Retry-After: 0
* HTTP error before end of send, stop sending
* abort upload
<
* shutting down connection #0
Your worker restarted mid-request. Please try sending the request again. Only GET or HEAD requests are retried automatically.
```
And the request looks like this:
``` shell
> curl -d @test.txt http://localhost:3000/api/v4/projects/1 --verbose
```
Where `test.txt` is a 2M file generated by this:
``` shell
> head -c 2000000 /dev/zero | tr '\0' 'a' > test.txt
```
## Tracing where the error was coming from
I tried to debug this, and found this was where the message was generated: https://github.com/cloudflare/workers-sdk/blob/wrangler%404.27.0/packages/wrangler/templates/startDevWorker/ProxyWorker.ts#L209
I tried to show what exactly the error was from `error`, and I got this message:
```
RangeError: Responses may only be constructed with status codes in the range 200 to 599, inclusive.
```
And that message was generated here: https://github.com/cloudflare/workerd/blob/v1.20250731.0/src/workerd/api/http.c%2B%2B#L917
I didn't look further yet, assuming this is an internal workerd bug. Could you please look into it?
## Our worker code
Our worker code for this is pretty simple. This is where `fetch` is called: https://gitlab.com/gitlab-org/cells/http-router/-/blob/8ff5b487f32d7c4a2dc8c128e77a0586054a32a3/src/rules/upstream.ts#L31
We only added a few headers to the request, and then forward everything else without touching anything. Our worker code doesn't get any errors and the error was coming from workerd internally when it actually tried to forward the request.
There's also no errors if the payload is only 200K with:
``` shell
> head -c 200000 /dev/zero | tr '\0' 'a' > test-smaller.txt
```
Contributor guide
Assessment
This issue has not been assessed yet.