2

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 "file=@big.file" -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.

Johan Book
  • 153
  • 1
  • 3
  • 10

2 Answers2

1

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.

Jamie
  • 537
  • 7
  • 12
0

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