Преглед на файлове

explicitly close Stream

reiji-h преди 1 година
родител
ревизия
efeb0f18d8
променени са 2 файла, в които са добавени 25 реда и са изтрити 2 реда
  1. 4 1
      apps/app/src/server/service/export.js
  2. 21 1
      apps/app/src/server/service/search-delegator/elasticsearch.ts

+ 4 - 1
apps/app/src/server/service/export.js

@@ -375,7 +375,10 @@ class ExportService {
     const output = fs.createWriteStream(zipFile);
     const output = fs.createWriteStream(zipFile);
 
 
     // pipe archive data to the file
     // pipe archive data to the file
-    archive.pipe(output);
+    archive
+      .on('error', () => { output.end() })
+      .pipe(output)
+      .on('error', () => { archive.destroy() });
 
 
     // finalize the archive (ie we are done appending files but streams have to finish yet)
     // finalize the archive (ie we are done appending files but streams have to finish yet)
     // 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand
     // 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand

+ 21 - 1
apps/app/src/server/service/search-delegator/elasticsearch.ts

@@ -554,11 +554,31 @@ class ElasticsearchDelegator implements SearchDelegator<Data, ESTermsKey, ESQuer
     });
     });
 
 
     readStream
     readStream
+      .on('error', () => {
+        batchStream.end();
+        appendTagNamesStream.end();
+        writeStream.end();
+      })
       .pipe(batchStream)
       .pipe(batchStream)
+      .on('error', () => {
+        readStream.destroy();
+        appendTagNamesStream.end();
+        writeStream.end();
+      })
       .pipe(appendTagNamesStream)
       .pipe(appendTagNamesStream)
+      .on('error', () => {
+        readStream.destroy();
+        batchStream.destroy();
+        writeStream.end();
+      })
       // .pipe(appendEmbeddingStream)
       // .pipe(appendEmbeddingStream)
       // .pipe(appendFileUploadedStream)
       // .pipe(appendFileUploadedStream)
-      .pipe(writeStream);
+      .pipe(writeStream)
+      .on('error', () => {
+        readStream.destroy();
+        batchStream.destroy();
+        appendTagNamesStream.destroy();
+      });
 
 
     return streamToPromise(writeStream);
     return streamToPromise(writeStream);
   }
   }