Skip to content

piped writeStream not closed on request-progress end event #36

@dlobsinger

Description

@dlobsinger

I am using the request-promise library to simplify the readability of a simple file download function. I came across an issue where the piped stream throws an error when it should already have been closed.

function causing errors
function download(uri,dest){ return new Promise(function(resolve, reject){ let req = request(uri); progress(req) .on('error', function (err) { reject(err); }) .on('end', function () { resolve() }) .pipe(fs.createWriteStream(dest)); }); }

workaround by piping from the request object
function download(uri,dest){ return new Promise(function(resolve, reject){ let req = request(uri); progress(req) .on('error', function (err) { reject(err); }) .on('end', function () { resolve() }); req.pipe(fs.createWriteStream(dest)); }); }

In my scenario I am downloading the file to a temporary location, and at some point after the download function resolves the file is deleted, causing an exception:
Error: ENOENT: no such file or directory, open '/tmp/B1q5rRTOZ/ry_OPC6_Z' ^ throw er; // Unhandled stream error in pipe. internal/streams/legacy.js:59

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions