This sounds good to me, I haven't tested how the microtaskqueue behaves when we call the TerminateExecution yet. I've been holding the HTTP connections at the C++ side while their requests are processed by the JS side, so it seems to be possible to recover this way. If I got it right you expect all promises to be rejected during the terminating process, right?
When you mentioned the "C++ response callbacks" did you mean my regular binds through which I send the responses or did you think about something special like a PromiseHook where I could identify the termination process? Thank you for your contribution, Cheers On Tuesday, February 9, 2021 at 3:01:28 AM UTC-3 Yang Guo wrote: > You can recover from termination. I'm not sure anymore how microtasks deal > with termination. Maybe they indeed get all rejected. One workaround is to > wrap every individual response handler execution in C++ callback which > calls into JS. When you terminate, you'd terminate the JS execution and > drop into the C++ callback. At that point you can cancel termination and > reject this one particular promise. > > Yang > > On Tue, 9 Feb 2021, 00:04 bambam, <[email protected]> wrote: > >> Thank you for your answer Yang, >> >> Let me give you a more detailed explanation: what I'm doing here is a >> server that runs untrusted code inside a v8::Isolate to process incoming >> HTTP requests and returns HTTP responses. Every time a request arrives, the >> same JS async function is called to process it, generating the >> corresponding response. What happens is that, for performance reasons, I >> need to process multiple requests in the same v8::Isolate, this is why I'm >> using an async function, this way every time a new request arrives I start >> processing it regardless of the previous requests' processing state. >> However, if at some point any of the running async functions block the V8, >> all the other async functions stop, because the CPU gets stuck. If I simply >> call v8::Isolate::TerminateExecution the CPU is released and all the system >> works again, however, all the async functions that weren't causing the >> system block are destroyed because the entire v8::Isolate is destroyed. >> What I need to do is to "destroy" only the async function that caused the >> system blocking and this is why I thought about promise "stopping" or >> "aborting" or "canceling" or anything like this. >> >> cheers, >> >> Bambam >> >> >> >> >> >> On Monday, February 8, 2021 at 7:42:52 PM UTC-3 Yang Guo wrote: >> >>> What you are looking for is not cancelling a promise, but stopping code >>> execution. JS is not concurrent, so rejecting or cancelling (which does not >>> exist for JS promises) wouldn't help. >>> >>> Take a look at v8::Isolate::TerminateExecution >>> >>> Cheers, >>> >>> Yang >>> >>> On Mon, 8 Feb 2021, 23:34 bambam, <[email protected]> wrote: >>> >>>> Hello guys... I'm embedding the V8 into my own application to run some >>>> untrusted code concurrently. Every untrusted code is executed inside a >>>> promise and when any of these codes blocks the system (by doing a >>>> while(true){} for example) I need to stop it. So, I've been trying to find >>>> a way of canceling JS promises but I haven't found anything useful. Does >>>> anyone here know where I could find some related information? >>>> >>>> -- >>>> -- >>>> v8-dev mailing list >>>> [email protected] >>>> http://groups.google.com/group/v8-dev >>>> --- >>>> You received this message because you are subscribed to the Google >>>> Groups "v8-dev" group. >>>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to [email protected]. >>>> To view this discussion on the web visit >>>> https://groups.google.com/d/msgid/v8-dev/6a499919-362f-48f9-8651-f8644f584255n%40googlegroups.com >>>> >>>> <https://groups.google.com/d/msgid/v8-dev/6a499919-362f-48f9-8651-f8644f584255n%40googlegroups.com?utm_medium=email&utm_source=footer> >>>> . >>>> >>> -- >> -- >> v8-dev mailing list >> [email protected] >> http://groups.google.com/group/v8-dev >> --- >> You received this message because you are subscribed to the Google Groups >> "v8-dev" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> > To view this discussion on the web visit >> https://groups.google.com/d/msgid/v8-dev/7c06dbd8-d692-42d2-ba28-04e5517623a1n%40googlegroups.com >> >> <https://groups.google.com/d/msgid/v8-dev/7c06dbd8-d692-42d2-ba28-04e5517623a1n%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > -- -- v8-dev mailing list [email protected] http://groups.google.com/group/v8-dev --- You received this message because you are subscribed to the Google Groups "v8-dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/v8-dev/c9da3a23-b91f-4cc7-921a-d6aa3d682f12n%40googlegroups.com.
