-
Notifications
You must be signed in to change notification settings - Fork 29.2k
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
Empty environment variables passed to vscode are unset #182560
Comments
Out of curiosity, are there any estimates on when this might be worked on? I would really like to move to a VSCode version newer than 1.73.1, but I can't do that while this issue is still outstanding. I'd be happy to try to look into the issue to see if I can fix it if that would be helpful. I'm not completely sure where |
@fedorareis it's currently on the backlog which means it doesn't have any estimated time. If you want to give it a shot here is where I'd start looking into it: Environment code in CLI: vscode/src/vs/code/node/cli.ts Lines 182 to 185 in 2d9cc42
Where we resolve "development environment" on Linux and macOS when launched via the dock: vscode/src/vs/platform/shell/node/shellEnv.ts Line 123 in 2d9cc42
Starting the extension host:
Note also that changing |
I think this bug is in Electron or Chromium. The release notes of 1.74 say that progress was made toward sandboxing VS Code, including the introduction of a new To confirm that the utility process fork is the thing removing the environment variable, we can log
Lines 234 to 237 in 3cd6f48
vscode/src/vs/platform/utilityProcess/electron-main/utilityProcess.ts Lines 236 to 244 in 3cd6f48
Lines 1 to 9 in 3cd6f48
|
Hey folks, I found it, it's in Chromium. I found a clue by accident: // Setting values in EnvironmentMap to an empty-string will make
// sure that they get unset from the environment via AlterEnvironment(). Which led me to the cause of it all: // Now append all modified and new values.
for (const auto& i : changes) {
if (!i.second.empty()) {
result_indices.push_back(value_storage.size());
value_storage.append(i.first);
value_storage.push_back('=');
value_storage.append(i.second);
value_storage.push_back(0);
}
} Chromium's Services API takes environment map entries with a blank value to mean that it shouldn't set the variable in a new process. It doesn't do it when you inherit the parent environment and don't pass any environment variables in because there's no need to alter the environment variables it already has. If you build Electron with this code in that for loop before the if statement, you can confirm that it isn't setting the variable when it launches the utility process: if (i.first == "EMPTY_VAR") {
LOG(INFO) << "It's unsetting the empty variable";
} Dobby has found the root cause of the bug. Dobby is free. (This is a lie. Dobby must file an issue with Chromium... some other time.) |
@deepak1556 this might be because of Chromium/Electron swallowing empty variables? |
@NoelTautges findings are on point, thanks! but this is not a bug in chromium, the launch API was not intended for external use cases and their behavior cannot be changed in upstream. However we can tweak the behavior for utility process in Electron. |
+1, just to add an additional datapoint, encountered the same behaviour with vscode-python extension as well. see microsoft/vscode-python#22337 |
This is a continuation of #174330 which is now locked and doesn't accept comments.
The original report was filed by our Go extension users who observed empty env vars were
not reflected when they run/debug tests using the extension's feature.
The issue was closed with #175682, which fixed env handling in the term env.
However, the Go extension features (run/debug tests) actually use extension host's
process.env
directly. So, the term environment fix doesn't help the original issue users are facing. (golang/vscode-go#2745)I prepared a repro in microsoft/vscode-extension-samples@main...hyangah:vscode-extension-samples:main#diff-665767c0f91ad3e1e028cc5dd145783e8ecaef232aefdb222ba9590b6bd52ba1
Either use the launch config in the commit, or
code-insiders (Version: 1.79.0-insider (Universal) Commit: 9084e08) gives me
You can see that EMPTY_VAR is undefined.
Is there a recommended way for extensions to get the process environment other than
process.env
?Does the node debugger avoid this issue in #174330 (comment) because the debugger/debugee is launched from a terminal?
The text was updated successfully, but these errors were encountered: