question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

This problem occurs when using node@15.2+ 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 https://github.com/nodejs/node/pull/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 node@15.1, but it hangs when using node@15.2 (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 node@15.2, 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()
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
HomerSpcommented, Dec 20, 2020

This issue has now been fixed in https://github.com/nodejs/node/pull/36563

1reaction
maleptcommented, Dec 22, 2020

For the record, the affected versions of Node.js were 15.2.0 through 15.4.0 inclusive. The fix mentioned was released in Node.js 15.5.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

nvm install node fails to install on macOS Big Sur M1 Chip
I'm trying to install the latest version of node using nvm. I've just got the newly released SIlicon Macbook Pro with the M1...
Read more >
Node.js Writable Stream Finish Not Firing In Class
When the CSV class is instantiated, it creates a writable stream to a file specified by the user. The write and destroy methods...
Read more >
Stream | Node.js v19.3.0 Documentation
Streams can be readable, writable, or both. All streams are instances of EventEmitter . To access the node:stream module: const stream = require('node:stream');...
Read more >
How To Work with Files Using Streams in Node.js - DigitalOcean
Streams are an efficient way to handle files in Node.js. In this tutorial, you'll create a command-line program, and then use it with ......
Read more >
Node.js file streams explained! - Arek Nawo
Streams can be readable, writable or both. Most of the "stream" module API as a whole, is targeted towards creating implementations of ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found