+ricea@On Wed, Nov 7, 2018 at 6:44 PM Yuki Shiino <yukis...@chromium.org> wrote:Hi V8-team and platform-architecture-dev,TL;DR: We'd like to extend v8::TryCatch APIs a little.We're having an issue how to handle worker termination, i.e. v8::Isolate termination. Roughly speaking, the situation is like below.Main thread:v8::Isolate* worker_isolate = ...;worker_isolate->TerminateExecution(); // Terminates the worker isolate.Worker thread (worker isolate):v8::TryCatch try_catch(isolate);DoSomethingWithV8(); // The Isolate terminates here.if (try_catch.HasCaught()) { // => true due to termination// Handle error or termination.return;}No problem so far. Worker thread MUST NOT run any V8 code no longer because the Isolate is terminating. However, Blink is not perfect, and it's pretty tough for Blink to stop everything with 100% correctness. Occasionally (or rarely) Blink continues running more V8 code like below.Worker thread (worker isolate):v8::TryCatch try_catch(isolate);DoSomethingElseWithV8();if (try_catch.HasCaught()) { // => false because no new exception is thrown inside the v8::TryCatch.return; // Blink doesn't reach here.}// Blink reach here instead. :(If v8::TryCatch::HasCaught() returned true, Blink would be able to handle it as error and Blink would work much better than now (Blink is now crashing).
So, proposals here are something like below (not yet so concrete).a) Make v8::TryCatch::HasCaught() return true if there already exists a pending exception. (Maybe this is no good.)b) Make a new API like v8::TryCatch::HasPendingException() and make it return true. Blink rewrites all HasCaught() to the new one.Similarly,a2) Make v8::TryCatch::Exception() return a pending exception if there already exists.b2) Make a new API like v8::TryCatch::PendingException() and make it return a thrown exception or pending exception in the isolate if any. Blink rewrites all Exception() to the new one.What do you think of the issue and proposals?Cheers,Yuki Shiino
--
You received this message because you are subscribed to the Google Groups "platform-architecture-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to platform-architect...@chromium.org.
To post to this group, send email to platform-arc...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/platform-architecture-dev/CABihn6ER8q9QABC3ROCSkm6V4w%2BDb0xEqRvjgzwBpMG9DmiG1Q%40mail.gmail.com.
Are you assuming that the worker is terminated while it's calling DoSomethingElseWithV8()? If yes, why does HasCaught() not return true? If no, what's a problem of continuing execution?
+adamk, cbruni to get more attention from V8 team. This needs V8 team's support.Actually, I intended haraken's (a3) at my proposal (a), but I'm afraid that changing an existing API HasCaught() would break backward compatibility. So, I'm also proposing to add a new V8 API like v8::TryCatch::HasPendingException or v8::TryCatch::HasCaughtOrTerminated or whatever we call it.By the way, the example code is just an example. Usually we don't have two TryCatch blocks next to each other, and Blink is rethrowing the exception in most cases. I just forgot to write rethrow in the example. That's not a point. Let me revise the example.Main thread:v8::Isolate* worker_isolate = ...;worker_isolate->TerminateExecution(); // Terminates the worker isolate.Worker thread (worker isolate):Foo(); // The v8::Isolate terminates during execution of Foo.Bar();where Foo and Bar are the followings.void Foo() {v8::TryCatch try_catch1(isolate);// Call V8 APIs. The v8::Isolate gets terminated at this point.if (try_catch1.HasCaught()) { // => true due to the termination exception.// Rethrow or report the error to global error handlers.return;}}void Bar() {v8::TryCatch try_catch2(isolate);// Call V8 APIs. V8 APIs fail because the isolate is terminating.if (try_catch2.HasCaught()) { // => false because no new exception is thrown inside |try_catch2| scope.// Rethrow or report the error to global error handlers.return;}// Blink reaches here. :(}
A proposed solution looks like the following.v8::TryCatch try_catch(isolate);// ...if (try_catch.HasCaughtOrTerminated()) {v8::Local<v8::Exception> exception = try_catch.CaughtExceptionOrTerminationException();// Do a job with |exception|.return;}where HasCaughtOrTerminated returns true when the isolate is terminating even if no exception is thrown inside the TryCatch scope, and CaughtExceptionOrTerminationException returns a thrown exception if an exception is thrown inside the TryCatch scope or the termination exception if the isolate is terminating.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/platform-architecture-dev/CABg10jx51JXHEt0H9z%3DzT%3D0GnhDf79QjhGtVxRc%3Dy-RXjHXUyw%40mail.gmail.com.
> As to the problem itself, I have a clarifying questions: doesn't Blink already have some choke point to determine whether it's "ok to call script now"? If so that'd be a more natural place to add this handling than TryCatch.No, there isn't such a point. To make matters worse, some call-sites don't check errors because they don't care.Sorry for the ignorance but I would like to know V8's policy on termination.1. What happens if the isolate is forcibly terminated (from another thread) while running a script? Will an exception be thrown? Is a v8::TryCatch catches the exception?2. What happens if we try to run a script when the isolate has already been terminated?3. What happens if v8 calls blink code, the isolate is forcibly terminated and then the control is back to v8?
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/platform-architecture-dev/CABihn6GKuTUs5UfpbQ6RwXq%3DWw0dDUJkq2JLzadnesfjLG%3DStg%40mail.gmail.com.
1. What happens if the isolate is forcibly terminated (from another thread) while running a script? Will an exception be thrown? Is a v8::TryCatch catches the exception?
2. What happens if we try to run a script when the isolate has already been terminated?
3. What happens if v8 calls blink code, the isolate is forcibly terminated and then the control is back to v8?
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/platform-architecture-dev/CAEvLGcKKKdZ4-Svz7NmXdzSaL9ryQz4cPEqhTfmWEURzwTdMqQ%40mail.gmail.com.
I found that at the only place Isolate::TerminateExecution is called from blink, V8 is not even running. That would mean that we don't have to worry about any of this?
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/platform-architecture-dev/CAFSTc_iBZUPpYMuUk3ouOe7cLBDizJFUjmcWuaAeVZfMBn4QqQ%40mail.gmail.com.
--
--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to the Google Groups "v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/platform-architecture-dev/CABihn6H0_3BFq5S2wv5Y8CDyW%3Dv-HjwskH1Wds6PmTWX5akE9g%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/platform-architecture-dev/CABihn6F4PfQJML_kNgt5Et2nhfQfVBuXYqaNyHyORAGtbVbEjg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/platform-architecture-dev/CABg10jz-oO0wE0ZGzdZ8%3DuXdZdj7UvR_KKG_12%2B_-67-LA_2Cw%40mail.gmail.com.
Would it be hard to make Blink immediately terminate the worker thread after E1 is forcibly terminated?Blink is already doing that for common script execution paths e.g., event listeners, call functions etc.
I could change V8 to not clear the termination exception so that we always stay in the terminated mode and not recover. However, from experience I expect tons of tests to fail if I implemented this change.
What you could do is add a check after E1 for v8::TryCatch::HasTerminated(), and schedule another Isolate::TerminateExecution() if true. You would need to do this for E2 as well, if you expect an E3, and so forth.
What you could do is add a check after E1 for v8::TryCatch::HasTerminated(), and schedule another Isolate::TerminateExecution() if true. You would need to do this for E2 as well, if you expect an E3, and so forth.That might be possible by migrating ExceptionState.RethrowV8Exception(v8::Local<v8::Value>) to ExceptionState.RethrowV8Exception(v8::TryCatch&). yukishiino@, how hard would it be?
I could change V8 to not clear the termination exception so that we always stay in the terminated mode and not recover. However, from experience I expect tons of tests to fail if I implemented this change.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/platform-architecture-dev/CAN0uC_Q%3Da8RqGpskEyJP-8voXk%3Dq_hPJxvyaxAnowFo1AC2LYw%40mail.gmail.com.