-
-
Notifications
You must be signed in to change notification settings - Fork 11.5k
Closed
Description
Describe the bug
- When the input stream is destroyed in the middle of sending data (premature close) then axios never ends sending request.
- When input stream emits error then axios will throw it as expected but application never ends probably because connection with server is never resolved (maybe leak).
To Reproduce
There are 3 variations which can be switched using the variation variable:
Variation 0: After one second stream sends some data and ends gracefully
Variation 1: After one second is stream destroyed
Variation 2: After one second is stream destroyed with error
let variation = 0;
let { PassThrough } = require("stream");
let http = require("http");
let axios = require("axios");
let server = http.createServer(async function(req, res)
{
for await (let chunk of req);
res.end("ok");
});
(async function()
{
await new Promise(resolve => server.listen(resolve));
let stream = new PassThrough();
setTimeout(function()
{
if(variation == 0) stream.end("abc");
if(variation == 1) stream.destroy();
if(variation == 2) stream.destroy(new Error("abc"));
}, 1000);
await axios.post("http://127.0.0.1:" + server.address().port, stream)
.then(res => console.log("received", res.data))
.catch(err => console.log("error", err));
console.log("request finished");
server.close();
}());Variation 0 proceeds normally:
received ok
request finished
Variation 1 never prints anything (axios is stuck in sending the request).
Variation 2 proceeds with error but application never terminates:
error Error: abc
...
request finished
(running forever)
Expected behavior
Variation 1 should print something like "premature close error" (ERR_STREAM_PREMATURE_CLOSE) as does require("stream").finished in such case (axios probably needs to listen on "close" event).
Variation 2 should gracefully end.
Environment
- Axios Version 0.21.1
- Adapter HTTP
- Node.js Version v15.12.0
Additional context/Screenshots
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels