Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

60 second timeout in http-proxy-middleware

I am seeing a 60 seconds timeout when using chimurai/http-proxy-middleware in Create-React-App and I cannot understand where it is coming from.

I am running an API on port 5000 and configured setupProxy.js as

const { createProxyMiddleware } = require("http-proxy-middleware");

const TIMEOUT = 30*60*1000;
module.exports = (app) => {
  app.use(
    "/api",
    createProxyMiddleware({
      target: "http://127.0.0.1:5000",
      changeOrigin: true,
      pathRewrite: {
        "^/api": "",
      },
      proxyTimeout: TIMEOUT,
      timeout: TIMEOUT,
      onError: (err, req, res) => console.log(err)
    })
  );
};

I generate a file using

dd if=/dev/zero of=large.file bs=1048576 count=2048

and then using curl

ENDPOINT="http://localhost:3000/api/v1/storage"
RATELIMIT=10M

curl -X POST $ENDPOINT -H "accept: application/json" -H "Content-Type: multipart/form-data" -F "[email protected]" -w "@curl-format.txt" --limit-rate $RATELIMIT --verbose

cURL yields

* Recv failure: Connection reset by peer
* stopped the pause stream!
* Closing connection 0

Same behavior is seen in browser (Chrome and Firefox).

In node v12.18.3 this was no problem, but it seems to be prevalent in v13.x and v14.x.

like image 778
Johan Book Avatar asked Dec 22 '25 01:12

Johan Book


2 Answers

I got the same. I found a solution here : https://npmmirror.com/package/http-proxy-middleware/v/1.2.0-beta.1.

Add this in your createProxyMiddleware parameters :

onProxyReq: fixRequestBody

like image 105
Franck Besson Avatar answered Dec 23 '25 15:12

Franck Besson


The timeout that is triggering this is coming from further up Node's HTTP stack. It seems that if POST body is being consumed as a stream, the headersTimeout doesn't get cancelled until the request body is fully uploaded.

Try setting server.headersTimeout to a large value, like server.headersTimeout = 1000 * 600.

There's currently an open issue on GitHub that seems related, so this may actually be a bug.

like image 32
Jamie Avatar answered Dec 23 '25 16:12

Jamie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!