-
Notifications
You must be signed in to change notification settings - Fork 29.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
worker: support case-insensitive process.env usage on Windows in worker threads #48976
Conversation
This patch fixes the reported issue by using a case-insensitive `unordered_map` for the copied `process.env` on Windows. Signed-off-by: Daeyeon Jeong <daeyeon.dev@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM if CI passes.
This comment was marked as outdated.
This comment was marked as outdated.
Signed-off-by: Daeyeon Jeong <daeyeon.dev@gmail.com>
This comment was marked as outdated.
This comment was marked as outdated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorta -.5 on this pull request. Yes, real environment variables are case-insensitive on Windows but deliberately mimicking that behavior for fake environment variables feels kind of yuck.
I expect it'll end up confusing people coding on Windows but deploying on Linux.
…indows Signed-off-by: Daeyeon Jeong <daeyeon.dev@gmail.com>
I understand the concern. Any mimicking could always break where we least expect it. And I think this issue also come from such a mimicking based on copied environment variables. In this case, do you think it would be better to document the limitation of the copy? Alternatively, if you have any other suggestions, I would be glad to hear them. |
This comment was marked as outdated.
This comment was marked as outdated.
You may want to get opinions from more people but that would be my suggestion, yes. |
I'm actually leaning towards that way too now. Will open another PR. |
// Test for https://github.com/nodejs/node/issues/48955. | ||
|
||
if (!common.isWindows) { | ||
common.skip('this test is Windows-specific.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wondering if it would make sense to modify this test for non-windows also to validate if the case-sensitivity is honoured.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it makes sense. That could be like:
const { isWindows } = require('../common');
if (isMainThread) {
process.env.barkey = 'foovalue';
strictEqual(process.env.BARKEY, isWindows ? process.env.barkey : undefined);
const worker = new Worker(__filename);
worker.once('message', (data) => {
strictEqual(data.BARKEY, isWindows ? data.barkey : undefined);
});
} else {
parentPort.postMessage({
barkey: process.env.barkey,
BARKEY: process.env.BARKEY,
});
}
I would follow up on this PR based on feedback regarding the document fix. Thanks.
Closing in favor of #49008 |
@bnoordhuis @daeyeon As a counterpoint: this current behaviour causes problems that are very confusing when coding on Linux but deploying on Windows (and I have hit issues related to this specifically in production). Similarly, it will cause confusion when just coding on Windows normally, regardless of deployments, when correct & worker-compatible code inexplicably works differently just because it was moved from the main thread into a worker. Is it possible to reconsider closing this? A motivating example:
Effectively unsetting environment variables unexpectedly could cause all sorts of serious problems, and is definitely confusing, even if it's documented. I wouldn't be surprised if the inconsistency more generally caused other weird edge cases. It would be much better to fix this so env vars on Windows always work the same everywhere, rather than just documenting the behaviour as broken in workers. |
Fixes: #48955
By default, a Worker thread uses a copy of parent thread's
process.env
, which is currently case-sensitive. It can be a problem on Windows using case-insensitive env keys, as reported issue.This fixes the issue by using a case-insensitive
unordered_map
for the copiedprocess.env
on Windows.Signed-off-by: Daeyeon Jeong daeyeon.dev@gmail.com