Merge pull request #109 from overleaf/spd-end-stream-on-premature-close

Call end() when handing ERR_STREAM_PREMATURE_CLOSE
This commit is contained in:
Simon Detheridge 2020-03-31 11:33:17 +01:00 committed by GitHub
commit 51a6dda660
2 changed files with 13 additions and 1 deletions

View file

@ -61,7 +61,12 @@ function getFile(req, res, next) {
}
pipeline(fileStream, res, err => {
if (err && err.code !== 'ERR_STREAM_PREMATURE_CLOSE') {
if (!fileStream.destroyed) {
fileStream.destroy()
}
if (err && err.code === 'ERR_STREAM_PREMATURE_CLOSE') {
res.end()
} else if (err) {
next(
new Errors.ReadError({
message: 'error transferring stream',

View file

@ -112,6 +112,13 @@ function getReadyPipeline(...streams) {
}
resolve(lastStream)
}
if (err) {
for (const stream of streams) {
if (!stream.destroyed) {
stream.destroy()
}
}
}
}
pipeline(...streams).catch(handler)