-
Notifications
You must be signed in to change notification settings - Fork 147
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
Cannot attach debugger to script #24
Comments
Hi @Muchaszewski, Thank you very much for providing such detailed information. Our initial thoughts:
Question: Can you easily reproduce this issue (the one in your last clip)? Does it happen if you run your application without the managed debugger? Thanks! |
This issue on second clip does happen without debugger connected and with Release as the target. I have 100% reproducibility, with multiple examples from my current codebase. I have managed to create simplified code that on my machine creates the similar error. using System.Dynamic;
using System.Text;
using System.Threading;
using Microsoft.ClearScript.V8;
public class Program
{
private static V8ScriptEngine Engine;
private static void Main(string[] args)
{
Engine = new V8ScriptEngine(V8ScriptEngineFlags.EnableDebugging |
V8ScriptEngineFlags.EnableRemoteDebugging);
var timeout = 0;
while (timeout < 200)
{
Thread.Sleep(5);
timeout += 1;
}
Engine.AddHostObject("foo", new Foo());
var script = new StringBuilder();
script.AppendLine("var element = [];");
for (var i = 0; i < 1201; i++) //Every value below or equal 1200 works
{
script.AppendLine("element.push(foo.bar({complex: \"element\"}));");
}
Engine.Execute(script.ToString());
Engine.Execute("debugger;");
}
public class Foo
{
public DynamicObject bar(DynamicObject obj)
{
//Yes I know this could be simplified :)
Engine.Execute("var __obj__ = {complex2: \"element2\", complex3: 3};");
return Engine.Script.__obj__;
}
}
} On my machine error shows only when you put more than 1200 into for loop that generates the first script. As you will run this code you will see that the problem is connected not to the long script but a number of additional scripts executions that inside Foo object. This bug at least on my machine is not executed with normal execution of multiple files one after another. for (var i = 0; i < 1201; i++)
{
//Works fine for me
Engine.Execute("var __obj__ = {complex2: \"element2\", complex3: 3};");
} Sometimes when I connect I have encountered something a bit different instead of not able to access any documents I receive following message in VSCode:
I will also add that this is working in 5.4 with legacy debugger connection. |
Hi @Muchaszewski, Thanks for posting your sample code. Unfortunately we still can't reproduce the issue, even when we raise the iteration count to 15000. Our procedure:
At this point VSCode connects and stops at Unlike the legacy debugging protocol, which is based on raw socket communications, Inspector is based on HTTP and WebSocket. Is it possible that you're running an aggressive web security product, or some other web traffic monitor that might be interfering? Thanks! |
I just have tried using a different machine with much more power. It seems like this is dependant on machine specification, not network specific. Same thing on the mobile internet, or without internet access, also from different PC with the same/similar processor. I can provide more detailed specification if you wish. If you are using even better processor please put this number higher as there is definitely an issue or use some low spec laptop, although I think this is more connected to VSCode, not ClearSciprt and highly depend on some resources like maximum instruction stack size available to the processor and stack overflow exception is handled in some bugged way. My thought is right now to allow programmatically from ClearSciprt to decide which documents debugger should consider "downloading" for debugging process, but this is just a workaround, not a solution. Thanks for all the support so far! Do you think there is any hope for my low spec work PC to be able to handle debugging with 5.5+ ClearScript? EDIT: My other idea is maybe you have a better way of creating new dynamic JavaScript objects from C# code then |
Hi @Muchaszewski, Hmm. On i7-6700K/16GB we successfully connected several times with the iteration count at 30000. However, it took a long time, during which we were in a state similar to what you saw. Eventually VSCode woke up and allowed us to view the loaded scripts, set breakpoints, etc. However, sometimes VSCode remained in that state even after the During several attempts VSCode because unresponsive. A few times it crashed. It could be that VSCode has scalability issues in this area. Have you tried Chrome DevTools? Currently ClearScript instances don't show up on chrome://inspect, but you can use an extension such as Node.js V8 Inspector to attach Chrome DevTools to ClearScript. We just tried it several times with the iteration count at 50000, and it worked every time, albeit quite slowly. Even if you find a debugger that works for you, we strongly recommend that you avoid creating so many scripts. V8 handles it fairly well, but it has its own limits, and the debuggers clearly aren't designed for it. Our recommendation is to minimize the number of times you invoke V8's parser. Reuse script code you've already parsed. For example, if you need to create many JavaScript objects from C#, create one function and call it as many times as necessary: dynamic createJsObject = engine.Evaluate("(function () { return {}; })");
var jsObjects = new object[100];
for (var i = 0; i < 100; ++i) {
jsObjects[i] = createJsObject();
} You can also create compiled scripts, which you can re-execute without recompilation. These techniques will ease debugging and improve your application's performance. Good luck! |
@ClearScriptLib thank you for your time and great support. Since I need only to create JavaScript objects from Json string I will do as you said to create one method that will create for me JavaScript objects using a precompiled method. //This execute once
var parseToJson = Engine.Compile("function __parseToJson(json) { return JSON.parse(json)}");
Engine.Execute(parseToJson);
//We can now execute this method everywhere in the program
var jsObject = Engine.Invoke("__parseToJson", jsonString); Also Node.js V8 Inspector works but with migration to 5.5. I will wait until the addition of "wait for debugger". Thanks again. |
This is follow up bug from #22
There are multiple issues but I think the reason is the same.
(around 20seconds)
Second is debugger connection
My code is too complicated to be pasted in the simple snippet for you to fiddle with, but it all falls down start V8Engine, wait a little bit of time (other code is executed) and then evaluate and execute.
Unfortunately, this code is "oversimplified" and connection to the debugger is established correctly.
A short description what is going on this gif.
Additional information:
Windows 10 x64 Version 10.0.15063 Build 15063
Visual Studio 2017 Community Version 15.4.0
VSCode 1.18.0 x64 Commit: dcee2202709a4f223185514b9275aa4229841aa7
Node 7.9.0
.NET Version of the project 4.6.1
ClearScript x64 built from Commit 3273d22
V8 Release x64 6.2.414.40
EDIT:
My Javascript code that is executed in this last gif is around 16000 lines of code. This might be connected to that. So simple example is working and my "Production code" is not.
The text was updated successfully, but these errors were encountered: