Closed misos1 closed 3 years ago
Ok, you are probably right. It can be simply solved through finally handler:
let { finished } = require("stream/promises");
let server = http.createServer(async function(req, res)
{
res.end(JSON.stringify(await probe(req, true).finally(() => finished(req.resume()))));
});
Possible output (when is req closed by probe then is sometimes not possible to send response):
When is server part changed to this then it freezes after some time (sending response does not dump partially read request anymore https://github.com/nodejs/node/commit/3d480dcf4c270cbf5a3acef08fc6b8d25576411b):
So neither true or false
keepOpen
does help here. Maybe would be good to have another option which will cause that source stream will be read (and ignored) to end after is probe successful. Or maybe it should do this whether it is successful or encountered error so also in case of error can be send meaningful error response to client.Maybe
keepOpen
set to true should actually mean (and be renamed to something else likedontClose
ordontDestroy
) that stream is not closed but read to end (dumped). Because stream which is not read to end or closed is really bad situation, for file stream this means leak, for http stream leak and possibly other problems as mentioned above. What is user supposed to do with partially read stream anyway? (Ok one possible use case is when is stream piped to multiple destinations, but I think there should be also option to read it to end by probe itself which covers also this situation anyway.)