Skip to content

writeFileListToStream might hang when the writable stream becomes full (asar does not work between Node 15.2.0 and 15.4.0) #210

@weedz

Description

@weedz

This problem occurs when using [email protected]+ under Linux (Pop!_OS 20.10). Also tested on Mac OS 11.1 (node 15.1, 15.2 and 15.4) but no problem there. EDIT: Was able to reproduce this on the Mac setup. Might just be that the Macbook is to slow to trigger this problem reliably...

This might be the relevant change in node nodejs/node#35348.

This is reproducible (at least on my machine) in my repository https://github.com/weedz/git-good. Running the command

$ npx electron-forge package

finishes when using [email protected], but it hangs when using [email protected] (also tested with version 15.4).

I then changed writeFileListToStream to wait for out.writableNeedDrain to become false. Now electron-forge package finishes when using [email protected], but this could probably be solved in a better way..

+ function sleep(ms) {
+     return new Promise((resolve, reject) => setTimeout(resolve, ms));
+ }

const writeFileListToStream = async function (dest, filesystem, out, list, metadata) {
    for (const file of list) {
+       while (out.writableNeedDrain) {
+           await sleep(10);
+       }
        if (file.unpack) { // the file should not be packed into archive
            const filename = path.relative(filesystem.src, file.filename)
            await copyFile(`${dest}.unpacked`, filesystem.src, filename)
        } else {
            await streamTransformedFile(file.filename, out, metadata[file.filename].transformed)
        }
    }
    return out.end()
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions