-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTTP: Connection resets after 60 seconds in node.js upload application #35661
Comments
I'm facing the same issue on the same platform. |
Do you think you could try to create a more minimal repro? Maybe without using node-fetch? |
For the moment no, however I was able to fuss with this a bit more. Setting Setting |
Experiencing the same issue on Node 12.9.0 but not Node 12.8.2. Could this change be related to the issue? |
I created a repro without node-fetch based on @ipbc-dev's code: https://github.com/neversun/node-issue-35661 There are 3 examples of a working (short) request, a long one with around 2 MB of data and a long but slow one with ~100KB of data. What I see is, that it works on 12.18.2 and fails on 12.19.0: {CLIENT} [read] 60.948s, size of read 16384, left 147456
{CLIENT} Error: socket hang up
at connResetException (internal/errors.js:609:14)
at Socket.socketOnEnd (_http_client.js:459:23)
at Socket.emit (events.js:326:22)
at endReadableNT (_stream_readable.js:1223:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
code: 'ECONNRESET'
} Also I found a strange thing to happen on 12.19.0 if you attach a timeout handler like... const server = http.createServer()
// server.on('request', async (req, res) => {
// ...
// })
server.on('timeout', () => {
console.log('timeout')
}) ...then the timeout handler is going to be called at around 60s. The request will come to a successful end then. EDIT: |
@nodejs/http |
The problem is in the server. Here's a minimal example with no dependencies. It creates a server and a client which opens a POST request and keeps transmitting all the time. After 8s it is considered a success. With Node 12.19.0 it fails after 5s with "Premature close". const http = require('http');
const stream = require('stream');
const time = () => new Date().toISOString();
const server = http.createServer((req, res) => {
console.log(time(), 'Received request');
stream.finished(req, (error) => {
console.error(time(), 'Stream error:', error && error.message);
process.exit(1);
});
});
server.headersTimeout = 5000;
server.listen(7000);
const options = {
host: 'localhost',
port: 7000,
path: '/',
method: 'POST',
headers: {
'Content-Type': 'application/x-octet-stream'
}
};
var req = http.request(options);
req.on('error', (err) => console.error(time(), 'client error', err));
// post the data
setInterval(() => req.write('hello'), 100);
setTimeout(() => {
console.log(time(), 'Success!');
process.exit(0);
}, 8000); Call stack on error:
|
I also suspect #34131. It doesn't reproduce with 14.14.0, so I suppose the backport was partial, or it depends on another commit that was not backported? |
Maybe missing da4d8de? |
Makes a lot of sense :) |
backport PR welcome |
Done: #35819 |
headers timeout should not occur *after* headers have been received. Fixes: nodejs#35661 PR-URL: nodejs#34578 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Fedor Indutny <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Pranshu Srivastava <[email protected]> (cherry picked from commit da4d8de)
headers timeout should not occur *after* headers have been received. Fixes: #35661 PR-URL: #34578 Backport-PR-URL: #35819 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Fedor Indutny <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Pranshu Srivastava <[email protected]> (cherry picked from commit da4d8de)
We've landed a fix in the 12.20.0-rc Could someone please check to see if this fixes their issues? |
This comment has been minimized.
This comment has been minimized.
headers timeout should not occur *after* headers have been received. Fixes: #35661 PR-URL: #34578 Backport-PR-URL: #35819 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Fedor Indutny <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Pranshu Srivastava <[email protected]> (cherry picked from commit da4d8de)
@MylesBorins Is it possible to provide a Docker image build? Then I could test it very quickly. |
All tests of my repro are passing with 12.20.0-rc.1 👍 |
@thomaslagies @scherermichael @seal-tf @seal-mt |
What steps will reproduce the bug?
The client depends on node-fetch v2.6.1
testServer.js
testClient.js
npm i node-fetch
node testServer.js
- This creates a new HTTP server listening on port 8081node testClient.js
How often does it reproduce? Is there a required condition?
The value inside RandomStream needs to be high enough to cause the request to take longer than 60 seconds.
What is the expected behavior?
In Node.js 10:
What do you see instead?
In Node.js 12:
Additional information
If there is any workaround, please let me know.
The text was updated successfully, but these errors were encountered: