Skip to content

[Bug]: Default proxy onError handler is keeping request open in broswer #4563

@miindlek

Description

@miindlek

Version

System:
    OS: macOS 15.3
    CPU: (10) arm64 Apple M1 Pro
    Memory: 81.33 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Browsers:
    Chrome: 133.0.6943.54
    Safari: 18.3

Details

I encountered a problem with the default onError handler of the server proxy.
At the moment the handler only logs the error. The response is not getting closed (which is normally done by calling res.end("...")). If an error happens, the request will stay open forever in the browser.

Here is the corresponding line:

const handleError = (err: unknown) => logger.error(err);

Since the default onError handler will be used, if no handler is passed, the default error handler of http-proxy-middleware will not be executed.
http-proxy-middleware is handling the error correctly by closing it, see:
https://github.com/chimurai/http-proxy-middleware/blob/1ee26edc1103e96e22b1d38b3de118bc21bfc57e/src/plugins/default/error-response-plugin.ts#L17

If no onError handler is configured, the requests keep staying in the pending state. In the console you can see, that the proxy error was already logged:
Image

After setting the onError handler to false, the default http-proxy-middleware error handler is used and the requests correctly resolve to an error:
Image

Setting the onError handler to false to get it to work is not intuitive and also not documented. We should either have a correct default handler, which closes the response, or we should not define a default handler, to let http-proxy-middleware handle it.

Reproduce link

https://codesandbox.io/p/github/miindlek/rsbuild-codesandbox-example/main?import=true

Reproduce Steps

  1. Open the dev console
  2. Click on the Button multiple times.
  3. See the network tab. Requests are still hanging.
  4. See the proxy already logged the error in the console.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions