question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proxy timeouts after 60 seconds

See original GitHub issue

Is this a bug report?

POST requests with form data seems to be timedout at 60 seconds. Happens in node version 13.x and 14.x but not 12.x. This might be a bug in node-http-proxy.

Steps to reproduce

  1. Create script testUpload.sh (or use scripts/testUpload.sh in supplied repo)
ENDPOINT=$1
FILE=large.file
RATELIMIT=10M

echo "Testing upload to $ENDPOINT"

if ! [ -f "$FILE" ]; then
  echo "Generating test file..."
  dd if=/dev/zero of=$FILE bs=1048576 count=2048
fi

echo "Testing upload at $RATELIMIT"

curl -X POST $ENDPOINT -H "accept: application/json" -H "Content-Type: multipart/form-data" -F "file=@${FILE}" --limit-rate $RATELIMIT --progress-bar --verbose -o ${RATELIMIT}.out
  1. Run script as testUpload.sh URL
  2. Wait for it

After 60 seconds I recieve

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

Simiar behavior is seen in browser.The request gets net::ERR_CONNECTION_RESET with error message TypeError: Failed to fetch in Chrome and TypeError: NetworkError when attempting to fetch resource. in Firefox.

Expected behavior

Request goes on until finished.

Actual behavior

Request vanishes. Our server got yielded client disconnected. Client never receives a response.

Setup

Frontend is created with Create-React-App with a separate API on port 5000. setupProxy.js is configured 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)
    })
  );
};

client info

The app is run inside Docker container based on node:14.5.0-alpine. Same error is encountered when run an Ubuntu system. This is the case for node versions 13.x and 14.x but not 12.x.

target server info

A Python FastAPI server that allows file uploads on endpoint POST /v1/storage.

Reproducible Demo

Here is a minimum working example of the front end1l; https://github.com/johanbook/http-proxy-middleware-upload-bug. Bash script included.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:11

github_iconTop GitHub Comments

16reactions
Mousakacommented, Oct 29, 2020

Found this line in my code base 😄

router.use(express.json()); // http-proxy-middleware stops working if this middleware is added before it.

Removing/Moving that middleware fixed my issue. Hopefully, this PR solves problems like this in the future

1reaction
sckimynwacommented, Jun 10, 2022

Found this line in my code base 😄

router.use(express.json()); // http-proxy-middleware stops working if this middleware is added before it.

Removing/Moving that middleware fixed my issue. Hopefully, this PR solves problems like this in the future

@Mousaka Thanks for your advice! I had a problem that this proxy-middlware works properly in GET and DELETE methods, but always PENDING-CANCELED in POST and PUT methods.

i think this is due to the body(payload) parsing. and when i moved middleware before the router.use(express.json()) It works like a charm. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Apache reverse proxy timeout in 60 seconds - Server Fault
Apache Default timeout is set to 300 seconds. This issue comes only when accessing website through apache reverse proxy. It works well by...
Read more >
Nginx times out exactly after 60 seconds - Stack Overflow
2. I am having 504 timeout at 60 seconds. · @AnkitChauhan it depends on which timeouts you want to have a longer duration....
Read more >
Long processes stop after 60s - 504 Gateway Time-out
So this means that nginx was waiting for Apache for 60 seconds and then aborted the request. So you still seem to have...
Read more >
How to Fix the 504 Gateway Timeout Error on Your Site - Kinsta
The 504 (Gateway Timeout) status code indicates that the server, while acting as a gateway or proxy, did not receive a timely response...
Read more >
Nginx Docker 504 Gateway Timeout after 60 seconds
We have a full docker container build with a digital ocean load balancer, an nginx webserver and a reverse proxy to the backend...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found