Comments (6)
@laverdet managed to patch Node.js for us that makes timeout and SIGINT work with pending Promises and other scheduled async code. Here is the patch:
diff --git a/src/node_contextify.cc b/src/node_contextify.cc
index ff66ffdaaa..c19d8e242e 100644
--- a/src/node_contextify.cc
+++ b/src/node_contextify.cc
@@ -857,22 +857,27 @@ class ContextifyScript : public BaseObject {
Local<Value> result;
bool timed_out = false;
bool received_signal = false;
+ env->isolate()->RunMicrotasks();
if (break_on_sigint && timeout != -1) {
Watchdog wd(env->isolate(), timeout);
SigintWatchdog swd(env->isolate());
result = script->Run();
+ env->isolate()->RunMicrotasks();
timed_out = wd.HasTimedOut();
received_signal = swd.HasReceivedSignal();
} else if (break_on_sigint) {
SigintWatchdog swd(env->isolate());
result = script->Run();
+ env->isolate()->RunMicrotasks();
received_signal = swd.HasReceivedSignal();
} else if (timeout != -1) {
Watchdog wd(env->isolate(), timeout);
result = script->Run();
+ env->isolate()->RunMicrotasks();
timed_out = wd.HasTimedOut();
} else {
result = script->Run();
+ env->isolate()->RunMicrotasks();
}
if (try_catch->HasCaught()) {
@@ -896,6 +901,16 @@ class ContextifyScript : public BaseObject {
try_catch->ReThrow();
return false;
+ } else if (timed_out || received_signal) {
+ // `isolate->IsExecutionTerminating()` returns false which I suspect is a
+ // bug in v8, but `CancelTerminateExecution()` still works
+ env->isolate()->CancelTerminateExecution();
+ if (timed_out) {
+ env->ThrowError("Script execution timed out.");
+ } else {
+ env->ThrowError("Script execution interrupted.");
+ }
+ return false;
}
if (result.IsEmpty()) {
We're now testing this patch on Node.js 7.10.0 on the PTR.
from driver.
Do we have any reliable method to disable async/await mechanic in Node.js?
from driver.
Since the node devs have marked this issue as "wontfix"[1] I'm getting the impression they're never going to resolve it. This may be one of those areas that needs an explicit rule telling people not to do it, with a punishment for those who do and maybe a mechanism on code upload to flag code for review by your team that may be breaking the rules. Otherwise I feel you're going to be playing whack-a-mole as people find ways to bypass things.
[1] nodejs/node#3020
from driver.
AFAIK theres no way to disable without recompiling node and/or v8 to disable it, even then I'm not sure it cna be disabled without modifying sources.
from driver.
We're trying to look into threaded architecture now. If we manage to separate event loops for every user, it will not only allow to control what user is executing within his loop, but also to isolate GC for this single user.
from driver.
This patch is deployed to production.
from driver.
Related Issues (17)
- Driver won't install HOT 2
- IVM 1.3.0 fails to compile HOT 3
- [Beta.8] publicSegments breaks user code HOT 1
- Failing to install on ARM HOT 3
- shardName should not be blank
- driver.getAllRooms was removed in 5.1.0
- Required dependencies are missing from package.json
- Script to regenerate map-grid-data.js based on current world map
- env.keys.STATUS_DATA should be env.keys.ROOM_STATUS_DATA HOT 1
- isolated-vm outdated
- Recommended shutdown method?
- Missing STD <limits> Headers for GCC 11+ HOT 1
- Update to Python 3 HOT 1
- HeuristicWeight should be allowed to be higher than 9
- `Game.notify()` messages get cut off at 500 characters
- Time sometimes goes backwards for a moment HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from driver.