Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/daemon/downloadable-artifact-http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ async function handleArtifactDownload(
didCleanupArtifact = true;
cleanupDownloadableArtifact(artifactId);
};
// Consume before the final chunk is written to the client: fetch treats a
// download as complete once content-length bytes arrive, which can happen
// before this stream emits 'end' (that needs one more threadpool read).
let bytesSent = 0;
stream.on('data', (chunk: string | Buffer) => {
bytesSent += chunk.length;
if (bytesSent >= artifact.sizeBytes) cleanupCompletedDownload();
});
stream.on('end', cleanupCompletedDownload);
res.on('finish', cleanupCompletedDownload);
res.on('close', () => {
Expand Down
Loading