-
Notifications
You must be signed in to change notification settings - Fork 30.5k
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
Vscode-specific issue with node-xmlhttprequest-sync: crashes Extension host in Windows; error is caught in MacOS; works as expected (no error) in Linux. #199492
Comments
After some digging, I found a more concise way to reproduce the error (independent of export function activate(context: vscode.ExtensionContext) {
// The command has been defined in the package.json file
// Now provide the implementation of the command with registerCommand
// The commandId parameter must match the command field in package.json
let disposable = vscode.commands.registerCommand('test.sync', () => {
try{
var XmlHttpRequest = require("xmlhttprequest").XMLHttpRequest;
let xmlHttp = new XmlHttpRequest();
xmlHttp.open("GET","",false);
xmlHttp.send("");
vscode.window.showInformationMessage(
"Response is: " + xmlHttp.responseText); // should return undefined
}catch(err){
console.log(err);
}
vscode.window.showInformationMessage("Hello world.");
});
context.subscriptions.push(disposable);
} Test in WSL: In Windows, this crashes the Extension Host. |
After some more digging around.. I think this issue might come from electron.. hopefully anyone here can confirm this? I made an electron fiddle that (I believe) causes electron to crash. You can find it here: https://gist.github.com/lopezvoliver/951784c060cd22bba0ef9d4c29019874 |
Ok, so after even more testing and from the response I got from the electron team (see issue here), here's an even more direct way to reproduce the inconsistent behavior for the vscode extension in windows vs Linux: export function activate(context: vscode.ExtensionContext) {
// The command has been defined in the package.json file
// Now provide the implementation of the command with registerCommand
// The commandId parameter must match the command field in package.json
let disposable = vscode.commands.registerCommand('test.sync', () => {
try{
var spawn = require("child_process").spawn;
var fs = require("fs");
var contentFile=".node-content-"+process.pid;
var syncFile = ".node-sync-"+process.pid;
var execString = "fs=require('fs');"
+"fs.writeFileSync('"+contentFile+"', '{}');"
+"fs.unlinkSync('"+syncFile+"');";
fs.writeFileSync(syncFile,"","utf8");
var syncProc = spawn(process.argv[0], ["-e", execString]);
while(fs.existsSync(syncFile)){
// Wait while the sync file is empty
}
var resp = JSON.parse(fs.readFileSync(contentFile, 'utf8'));
// Kill the child process once the file has data
syncProc.stdin.end();
// Remove the temporary file
fs.unlinkSync(contentFile);
vscode.window.showInformationMessage("Response is : " + resp.empty);
}catch(err){
console.log(err);
}
vscode.window.showInformationMessage("Hello world.");
});
context.subscriptions.push(disposable);
} This sort of simulates what According to the
I made a quick test in Electron, and indeed I can confirm that it does not work, even in Linux. So my conclusion is that there is some vscode magic going on that makes the above example work in Linux.. So.. where is this magic and can it be implemented to work also in Windows? |
Finally, after going down the rabbit hole even more, the issue is In Windows, this pointed to With this information, I can now make a patch for this in my extension, so I will close this issue. |
Type: Bug
I am developing an extension that wraps some features from the @google/earthengine javascript API.
Some of these features can be called either synchronously or can be provided with a callback function. The following minimal reproducible example works as expected when running directly in node, regardless of the environment or OS:
where
EETOKEN
is a short-lived token required to use the earthengine API.However, running this same code from within a vscode extension results in very different behavior depending on the OS:
Given that the error doesn't occur anywhere when running through node, i.e. it is vscode-specific, I don't expect this to be a bug in the earthengine api. Therefore, I am opening the issue here.
Here is an animation showing the extension working as expected in WSL:
Here is an animation showing the extension working as expected in Windows (with the synchronous call removed):
Finally, here is an animation showing the behavior of the Extension host when the synchronous call is included in Windows:
Finally, here is what a minimal extension command would look like to reproduce the issue:
VS Code version: Code - Insiders 1.85.0-insider (b3b84b5, 2023-11-28T12:02:59.475Z)
OS version: Windows_NT x64 10.0.19045
Modes:
System Info
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Extensions (8)
A/B Experiments
The text was updated successfully, but these errors were encountered: