Fix FS drops connection if download is too slow
Only happens in HTTPS because seemingly somewhere in the stack up to 50mb of data is being buffered potentially triggering a timeout at a higher level if not drained fast enough. This commit also includes other streams related improvements.
This commit is contained in:
1 parent
d53e10f62d
commit
d1c01e0848
3 files changed
+48
-50
No files matched your search
+12
-3
@@ -23,7 +23,7 @@ import { onConnect, optimizeProjection } from "../db";
|
||||
import * as mongodbFunctions from "../mongodb-functions";
|
||||
import * as expression from "../common/expression";
|
||||
import { QueryOptions, Expression } from "../types";
|
||||
import { Readable, Writable } from "stream";
|
||||
import { Readable } from "stream";
|
||||
import { minimize } from "../common/boolean-expression";
|
||||
|
||||
const RESOURCE_COLLECTION = {
|
||||
@@ -342,10 +342,19 @@ export function putFile(
|
||||
metadata: metadata,
|
||||
}
|
||||
);
|
||||
|
||||
contentStream.on("close", () => {
|
||||
if (!contentStream.readableEnded)
|
||||
uploadStream.destroy(new Error("Stream closed prematurely"));
|
||||
});
|
||||
|
||||
contentStream.on("error", (err) => {
|
||||
uploadStream.destroy(err);
|
||||
});
|
||||
|
||||
uploadStream.on("error", reject);
|
||||
contentStream.on("error", reject);
|
||||
uploadStream.on("finish", resolve);
|
||||
contentStream.pipe(uploadStream as Writable);
|
||||
contentStream.pipe(uploadStream);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user