Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
c87ed21
assert: port common.mustCall() to assert
DavenportEmma Feb 27, 2020
4423304
vm: throw error when duplicated exportNames in SyntheticModule
himself65 Apr 13, 2020
8c40ffc
tools: update broken types in type parser
cjihrig Apr 25, 2020
8d5ac1b
wasi: rename __wasi_unstable_reactor_start()
cjihrig Apr 26, 2020
d7d9960
wasi: update start() behavior to match spec
cjihrig Apr 26, 2020
8325c29
deps: update to uvwasi 0.0.8
cjihrig Apr 26, 2020
ed45b51
path: fix comment grammar
thecodrr Apr 20, 2020
ec24577
v8: use AliasedBuffers for passing heap statistics around
joyeecheung Apr 19, 2020
542da43
lib: fix validateport error message when allowZero is false
rickyes Apr 15, 2020
aced1f5
test: flaky test-stdout-close-catch on freebsd
sam-github Apr 14, 2020
f79ef96
test: mark test flaky on freebsd
sam-github Apr 14, 2020
3cb1713
http2,doc: minor fixes
mildsunrise Apr 27, 2020
db293c4
cluster: fix error on worker disconnect/destroy
santigimeno Apr 1, 2020
637442f
crypto: key size must be int32 in DiffieHellman()
bnoordhuis Apr 10, 2020
e07cca6
crypto: generator must be int32 in DiffieHellman()
bnoordhuis Apr 10, 2020
83e165b
crypto: check DiffieHellman p and g params
bnoordhuis Apr 10, 2020
c49e3ea
console: support console constructor groupIndentation option
rickyes Apr 21, 2020
10a87c8
src: remove unnecessary fully qualified names
rickyes Apr 26, 2020
12426f5
tools: update remark-preset-lint-node@1.14.0
Trott Apr 26, 2020
c5a2f9a
doc: fix markdown parsing on doc/api/os.md
juanarbol Apr 25, 2020
466213d
n-api: simplify uv_idle wrangling
bnoordhuis Apr 22, 2020
82e459d
doc: don't check links in tmp dirs
bnoordhuis Apr 22, 2020
92c7e06
test: check args on SourceTextModule cachedData
juanarbol Apr 20, 2020
b183d0a
stream: let Duplex re-use Writable properties
ronag Apr 26, 2020
289a5c8
doc: some grammar fixes
ChrisAHolland Apr 26, 2020
de15edc
doc: improve worker pool example
ranjan-purbey Apr 26, 2020
3c2f608
test: correct typo in test name
cjihrig Apr 27, 2020
c6d632a
worker: unify custom error creation
addaleax Apr 27, 2020
bc9e413
worker: add stack size resource limit option
addaleax Apr 27, 2020
bc40ed3
stream: add null check in Readable.from
rexagod Apr 16, 2020
2396219
doc: correct Nodejs to Node.js spelling
nschonni Apr 27, 2020
541ea03
src: separate out NgLibMemoryManagerBase
jasnell Apr 27, 2020
eab4be1
lib: cosmetic change to builtinLibs list for maintainability
jasnell Apr 27, 2020
f4e5ab1
src: crypto::UseSNIContext to use BaseObjectPtr
jasnell Apr 27, 2020
f61928b
src: return undefined when validation err == 0
jasnell Apr 27, 2020
3866dc1
wasi: use free() to release preopen array
addaleax Apr 28, 2020
de643bc
src: use unique_ptr for CachedData in ContextifyScript::New
addaleax Apr 28, 2020
9ccb6b2
test: add missing calls to napi_async_destroy
addaleax Apr 28, 2020
af7da46
test: fix out-of-bound reads from invalid sizeof usage
addaleax Apr 28, 2020
f62d92b
build: add --error-on-warn configure flag
danbev Apr 6, 2020
a87d371
tools: fix redundant-move warning in inspector
danbev Apr 6, 2020
5eccf1e
module: no type module resolver side effects
guybedford Apr 27, 2020
4cfa7e0
stream: simplify Readable push/unshift logic
himself65 Apr 17, 2020
d39254a
vm: fix vm.measureMemory() and introduce execution option
joyeecheung Apr 22, 2020
45032a3
stream: fix stream.finished on Duplex
ronag Apr 28, 2020
89ed7a5
test: move test-process-title to sequential
addaleax Apr 29, 2020
c5a4534
deps: V8: backport e29c62b74854
addaleax Apr 28, 2020
e276524
test: skip memory usage tests when ASAN is enabled
addaleax Apr 28, 2020
451993e
http: set default timeout in agent keepSocketAlive
omsmith Apr 28, 2020
a990137
doc: fix the spelling error in stream.md
yunnysunny Feb 1, 2020
36d5002
doc: clarify when not to run CI on docs
juanarbol Apr 27, 2020
d02ced8
doc: add util.types.isArrayBufferView()
kevinoid Apr 27, 2020
6734cc4
tools: bump remark-preset-lint-node to 1.15.0
Trott Apr 30, 2020
bb2d2f6
src: remove unused v8 Message namespace
edsadr Apr 30, 2020
7893bde
doc: fix a typo in crypto.generateKeyPairSync()
himself65 May 1, 2020
a4ec01c
http: simplify sending header
ronag May 1, 2020
2174159
esm: improve commonjs hint on module not found
dnlup Mar 21, 2020
413f5d3
doc: add missing deprecation not
ronag May 1, 2020
60ebbc4
test: update c8 ignore comment
Apr 30, 2020
74b0e8c
http: ensure client request emits close
ronag Apr 30, 2020
6925b35
doc: mark assert.CallTracker experimental
BridgeAR Apr 28, 2020
d68f78f
2020-05-05, Version 14.2.0 (Current)
targos May 4, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
worker: unify custom error creation
Mostly, this introduces a pattern that makes sure that if a custom
error is reported, `stopped_` will be set to `true` correctly in
every cast, which was previously missing for the
`NewContext().IsEmpty()` case (which led to a hard crash from the
`Worker` destructor).

This also leaves TODO comments for a few cases in which
`ERR_WORKER_OUT_OF_MEMORY` was not used in accordance with the
documentation for that error code (or according to its intention).
Fixing that is semver-major.

PR-URL: #33084
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
addaleax authored and targos committed May 4, 2020
commit c6d632a72aa6f980a1dec78ac869a64828e4f312
30 changes: 17 additions & 13 deletions src/node_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ class WorkerThreadData {
if (ret != 0) {
char err_buf[128];
uv_err_name_r(ret, err_buf, sizeof(err_buf));
w->custom_error_ = "ERR_WORKER_INIT_FAILED";
w->custom_error_str_ = err_buf;
w->stopped_ = true;
w->Exit(1, "ERR_WORKER_INIT_FAILED", err_buf);
return;
}
loop_init_failed_ = false;
Expand All @@ -148,9 +146,9 @@ class WorkerThreadData {

Isolate* isolate = Isolate::Allocate();
if (isolate == nullptr) {
w->custom_error_ = "ERR_WORKER_OUT_OF_MEMORY";
w->custom_error_str_ = "Failed to create new Isolate";
w->stopped_ = true;
// TODO(addaleax): This should be ERR_WORKER_INIT_FAILED,
// ERR_WORKER_OUT_OF_MEMORY is for reaching the per-Worker heap limit.
w->Exit(1, "ERR_WORKER_OUT_OF_MEMORY", "Failed to create new Isolate");
return;
}

Expand Down Expand Up @@ -233,9 +231,7 @@ class WorkerThreadData {
size_t Worker::NearHeapLimit(void* data, size_t current_heap_limit,
size_t initial_heap_limit) {
Worker* worker = static_cast<Worker*>(data);
worker->custom_error_ = "ERR_WORKER_OUT_OF_MEMORY";
worker->custom_error_str_ = "JS heap out of memory";
worker->Exit(1);
worker->Exit(1, "ERR_WORKER_OUT_OF_MEMORY", "JS heap out of memory");
// Give the current GC some extra leeway to let it finish rather than
// crash hard. We are not going to perform further allocations anyway.
constexpr size_t kExtraHeapAllowance = 16 * 1024 * 1024;
Expand Down Expand Up @@ -292,8 +288,9 @@ void Worker::Run() {
TryCatch try_catch(isolate_);
context = NewContext(isolate_);
if (context.IsEmpty()) {
custom_error_ = "ERR_WORKER_OUT_OF_MEMORY";
custom_error_str_ = "Failed to create new Context";
// TODO(addaleax): This should be ERR_WORKER_INIT_FAILED,
// ERR_WORKER_OUT_OF_MEMORY is for reaching the per-Worker heap limit.
Exit(1, "ERR_WORKER_OUT_OF_MEMORY", "Failed to create new Context");
return;
}
}
Expand Down Expand Up @@ -682,9 +679,16 @@ Local<Float64Array> Worker::GetResourceLimits(Isolate* isolate) const {
return Float64Array::New(ab, 0, kTotalResourceLimitCount);
}

void Worker::Exit(int code) {
void Worker::Exit(int code, const char* error_code, const char* error_message) {
Mutex::ScopedLock lock(mutex_);
Debug(this, "Worker %llu called Exit(%d)", thread_id_.id, code);
Debug(this, "Worker %llu called Exit(%d, %s, %s)",
thread_id_.id, code, error_code, error_message);

if (error_code != nullptr) {
custom_error_ = error_code;
custom_error_str_ = error_message;
}

if (env_ != nullptr) {
exit_code_ = code;
Stop(env_);
Expand Down
7 changes: 5 additions & 2 deletions src/node_worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ class Worker : public AsyncWrap {
void Run();

// Forcibly exit the thread with a specified exit code. This may be called
// from any thread.
void Exit(int code);
// from any thread. `error_code` and `error_message` can be used to create
// a custom `'error'` event before emitting `'exit'`.
void Exit(int code,
const char* error_code = nullptr,
const char* error_message = nullptr);

// Wait for the worker thread to stop (in a blocking manner).
void JoinThread();
Expand Down