Explorar el Código

Destroy file-download stream on error

Simon Detheridge hace 6 años
padre
commit
87b8f8e194
Se han modificado 1 ficheros con 12 adiciones y 9 borrados
  1. 12 9
      services/filestore/app/js/FileController.js

+ 12 - 9
services/filestore/app/js/FileController.js

@@ -61,15 +61,18 @@ function getFile(req, res, next) {
     }
 
     pipeline(fileStream, res, err => {
-      if (err && err.code === 'ERR_STREAM_PREMATURE_CLOSE') {
-        res.end()
-      } else if (err) {
-        next(
-          new Errors.ReadError({
-            message: 'error transferring stream',
-            info: { bucket, key, format, style }
-          }).withCause(err)
-        )
+      if (err) {
+        fileStream.destroy()
+        if (err.code === 'ERR_STREAM_PREMATURE_CLOSE') {
+          res.end()
+        } else {
+          next(
+            new Errors.ReadError({
+              message: 'error transferring stream',
+              info: { bucket, key, format, style }
+            }).withCause(err)
+          )
+        }
       }
     })
   })