caoccao / Javet

Javet is Java + V8 (JAVa + V + EighT). It is an awesome way of embedding Node.js and V8 in Java.
https://www.caoccao.com/Javet/
Apache License 2.0
698 stars 68 forks source link

V8Inspector.sendRequest() blocked in different thread when script is paused #139

Open zjgg888 opened 2 years ago

zjgg888 commented 2 years ago

Execute a script and pause it by setbreakpoint using V8Inspector before (executing script in thread1), when the script is paused, use V8Inspector.sendRequest('Debugger.resume') to resume execution (resume script in thread2), it blocked at v8Native.v8InspectorSend(v8Runtime.getHandle(), message);

caoccao commented 2 years ago

I haven't tested the scenario you posted here.

Here are my thoughts for your reference. The current implementation is the internal lock is held by the execution thread because that thread doesn't know it is paused. That internal lock prevents other threads from executing anything including the V8 inspector. That design might be wrong.

Could you leave your minimal reproduceable code snippet and your expected result?

zjgg888 commented 2 years ago

Sorry,it's hard to take code snippet from my project. Also, I used to dispatch inspector message in J2V8 is in 'waitFrontendMessageOnPause' callback,this callback gives a chance to do something when script paused.

caoccao commented 2 years ago

That would make it hard for me to troubleshoot. Do you mind joining the discord server to discuss with me in detail? I still need a code snippet.

caoccao commented 2 years ago

I think this issue is not merely on Android but on all operating systems. There seems to be a flaw in the locking mechanism. I think Javet needs to detect a break point hit event and release the lock accordingly. It's a considerable change which requires a certain amount of dev time.

caoccao commented 7 months ago

It's been so long. I just submitted a fix to the dev branch. Do you mind taking a try? The snapshot build is at Actions.