Просмотр исходного кода

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

Call end() when handing ERR_STREAM_PREMATURE_CLOSE
Simon Detheridge 6 лет назад
Родитель
Сommit
51a6dda660

+ 6 - 1
services/filestore/app/js/FileController.js

@@ -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',

+ 7 - 0
services/filestore/app/js/PersistorHelper.js

@@ -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)