Repository: next.js
Issue: Next.JS 15 RC freezes occasionally when forwarding (`rewrites()`)  requests to FastAPI endpoint
Labels: bug,Middleware

### Link to the code that reproduces this issue

https://github.com/reasv/panoptikon-ui/blob/master/next.config.mjs

### To Reproduce

I do not have a minimal or reliable way of reproducing this issue as it seems to happen inconsistently, but this behaviour seems clearly incorrect to me, and perhaps we can isolate the problem causing it.

Above, I linked the configuration that seems to reproduce the issue with my FastAPI server, specifically the endpoint serving thumbnails:
https://github.com/reasv/panoptikon/blob/master/src/panoptikon/api/routers/items.py#L200
^This is the line of code returning the response that occasionally makes Next.js hang up. As you can see it's just a file response.
When forwarding to this endpoint using the config I linked in the main link, the issue occurs, occasionally, and not consistently with the same files/same requests.

The FastAPI server itself prints this error:
```
RuntimeError: Response content shorter than Content-Length
```
Which led me to blame FastAPI at first, but then I realized that fastAPI itself remained responsive throughout, while Next.JS seemingly freezes, often not serving *any* requests.

Maybe it is an error caused by FastAPI, but this doesn't seem like a robust way of handling it.

### Current vs. Expected behavior

I expect Next.JS to forward my requests to the server's API and return the responses. I am using forwards to avoid cross-origin requests and to allow for *runtime* configurable API URLs, through serverside-only env variables, which otherwise would have to be baked into the build.

This works most of the time using the forwards provided above. Unfortunately, at seemingly random times, the thumbnail endpoint, which returns image files, seems to have issues. The image either does not load on the client, or it half-loads with the remaining part being empty.
Next.js eventually prints ECONNRESET errors, but that happens after a *while*, in the meantime, next.js becomes varying degrees of unresponsive, to the point of sometimes not being able to refresh the page.
Loading the image directly from the FastAPI endpoint bypassing next.js right when this happens yields no hangups, and works flawlessly whenever I tried it.
Meanwhile, if I try to open the image (for a 'broken' image) in a new tab, using the forwarded next.js link, it usually just hangs and loads for a while.

I want to stress that Next.js isn't printing errors while frozen either, the ECONNRESET errors happen after a *while*, so I believe something is definitely wrong, because when it is in a frozen state, often nothing seems to load, instead making the browser wait indefinitely with no console feedback for a while.

I am not 100% sure Next.js is fully to blame here, but it probably shouldn't be freezing like this no matter what.
Sometimes it isn't totally frozen and I can keep navigating, getting some broken images. I suspect the number of failed forwards might influence how responsive Next.js remains.

I should note that I am using the React Compiler as well as React 19 and Next.js 15 RC-0.

### Provide environment information

```bash
Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 10 Pro
  Available memory (MB): 64660
  Available CPU cores: 32
Binaries:
  Node: 18.17.0
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 15.0.0-rc.0 // Latest available version is detected (15.0.0-rc.0).        
  eslint-config-next: N/A
  react: 19.0.0-rc-f994737d14-20240522
  react-dom: 19.0.0-rc-f994737d14-20240522
  typescript: 5.5.4
Next.js Config:
  output: N/A
```


### Which area(s) are affected? (Select all that apply)

Middleware

### Which stage(s) are affected? (Select all that apply)

next dev (local)

### Additional context

I've only run this in the environment specified, and I will reiterate that I am using React 19 RC and React Compiler.