Proxy timeouts after 60 seconds
See original GitHub issueIs 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
- Create script
testUpload.sh
(or usescripts/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
- Run script as
testUpload.sh URL
- 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:
- Created 3 years ago
- Reactions:5
- Comments:11
Top GitHub Comments
Found this line in my code base 😄
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
andDELETE
methods, but alwaysPENDING-CANCELED
inPOST
andPUT
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!