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
11 changes: 10 additions & 1 deletion lib/worker/lib/workerLib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,19 @@ export class Parent extends RequesterResponder {
/** start worker */
startWorker(childJsPath: string, terminalError: (e: Error) => any, customArguments: string[]) {
try {
/** At least on NixOS, the environment must be preserved for
dynamic libraries to be properly linked.
On Windows/MacOS, it needs to be cleared, cf. atom/atom#2887 */
var spawnEnv = (process.platform === 'linux') ? Object.create(process.env) : {};
spawnEnv['ATOM_SHELL_INTERNAL_RUN_AS_NODE'] = '1';
Copy link
Member

Choose a reason for hiding this comment

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

Issues:

a.) You are mutating process.env here ... that is bad
b.) Using process.env as a whole breaks using atom as node on windows. See : atom/atom#2887 (comment) and independently verified : atom/atom#2887 (comment)

Solutions :

  • Use Object.create around process.env
  • only do if platform is NixOS

Thanks for finding the bug 🌹

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yes, oops! I will fix that.

Do you have an existing way of checking the operating system?

Copy link
Member

Choose a reason for hiding this comment

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

Do you have an existing way of checking the operating system?

process.platform https://nodejs.org/api/process.html#process_process_platform although I don't know the value for NixOS .... I'd be okay with whatever that is as long as its not mac / windows :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It has value 'linux' under NixOS.
I can set it that way, though I am not able to test on many such operating systems.

this.child = spawn(this.node, [
// '--debug', // Uncomment if you want to debug the child process
childJsPath
].concat(customArguments), { cwd: path.dirname(childJsPath), env: { ATOM_SHELL_INTERNAL_RUN_AS_NODE: '1' }, stdio: ['ipc'] });
].concat(customArguments), {
cwd: path.dirname(childJsPath),
env: spawnEnv,
stdio: ['ipc']
});

this.child.on('error', (err) => {
if (err.code === "ENOENT" && err.path === this.node) {
Expand Down