Skip to content

Conversation

@dcodeIO
Copy link

@dcodeIO dcodeIO commented Nov 22, 2024

This PR removes all blocking operations (child_process.execSync and fs.readSync) from the library and replaces them with asynchronous equivalents while keeping the public API intact.

The diff is intentionally boring, focusing solely on this change and minor related cleanup to minimize the risk of introducing accidental breakage.

Fixes #873. Keep it up!

Comment on lines -1139 to -1183
function promisifySave(nodeStyleFunction) {
return function () {
const args = Array.prototype.slice.call(arguments);
return new Promise(function (resolve) {
args.push(function (err, data) {
resolve(data);
});
nodeStyleFunction.apply(null, args);
});
};
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This utility function had exactly one usage, where now a .catch(() => '') is utilized in its place.

@lukechilds
Copy link

lukechilds commented Nov 23, 2024

Just fyi @sebhildebrandt systeminformation causes major performance issues and event loop deadlocks when used in server applications. This PR fixes it.

https://nodejs.org/en/learn/asynchronous-work/dont-block-the-event-loop

We're running this fork at @getumbrel with great results but we'd love to come back to upstream once this is merged 🙏

@Spartan-Hex-Shadow
Copy link

@sebhildebrandt would you be able to include this in the next release?

@sebhildebrandt
Copy link
Owner

@Spartan-Hex-Shadow, @dcodeIO , @lukechilds ... the next major release (6.0) is a complete rewrite (TS) where we do not have any sync functions. This should then be solved.

@sylt
Copy link

sylt commented Dec 19, 2024

@sebhildebrandt Even though it is fixed in the next major release in a more rigorous way, perhaps there would be no harm in having it fixed in the current major release? Unless you see any problems with this PR, of course.

@dcodeIO
Copy link
Author

dcodeIO commented Jan 13, 2025

Merged master into this branch, so it now includes the fix for GHSA-cvv5-9h9w-qp2m. It appears that one new sync call has been introduced to master since, and it looks like it affects the public API, so all I could reasonably do was add a TODO.

@Spartan-Hex-Shadow
Copy link

@sebhildebrandt can we get this merged as an incremental v5 release?

Comment on lines +45 to 46
// TODO: Shouldn't be synchronous but is part of the public API
const stdout = execSync('date +%Z && date +%z && ls -l /etc/localtime 2>/dev/null', util.execOptsLinux);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this will work since the import of "execSync" is removed above?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Awaiting promises returned by systeminformation can still block running thread

5 participants