| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 5b5e272 commit 5983568
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -328,7 +328,10 @@ void Worker::Run() { | |||
| 328 | 328 | Debug(this, "Created Environment for worker with id %llu", thread_id_.id); | |
| 329 | 329 | if (is_stopped()) return; | |
| 330 | 330 | { | |
| 331 | - CreateEnvMessagePort(env_.get()); | ||
| 331 | + if (!CreateEnvMessagePort(env_.get())) { | ||
| 332 | + return; | ||
| 333 | + } | ||
| 334 | + | ||
| 332 | 335 | Debug(this, "Created message port for worker %llu", thread_id_.id); | |
| 333 | 336 | if (LoadEnvironment(env_.get(), StartExecutionCallback{}).IsEmpty()) | |
| 334 | 337 | return; | |
@@ -352,17 +355,24 @@ void Worker::Run() { | |||
| 352 | 355 | Debug(this, "Worker %llu thread stops", thread_id_.id); | |
| 353 | 356 | } | |
| 354 | 357 | ||
| 355 | - void Worker::CreateEnvMessagePort(Environment* env) { | ||
| 358 | + bool Worker::CreateEnvMessagePort(Environment* env) { | ||
| 356 | 359 | HandleScope handle_scope(isolate_); | |
| 357 | - Mutex::ScopedLock lock(mutex_); | ||
| 360 | + std::unique_ptr<MessagePortData> data; | ||
| 361 | + { | ||
| 362 | + Mutex::ScopedLock lock(mutex_); | ||
| 363 | + data = std::move(child_port_data_); | ||
| 364 | + } | ||
| 365 | + | ||
| 358 | 366 | // Set up the message channel for receiving messages in the child. | |
| 359 | 367 | MessagePort* child_port = MessagePort::New(env, | |
| 360 | 368 | env->context(), | |
| 361 | - std::move(child_port_data_)); | ||
| 369 | + std::move(data)); | ||
| 362 | 370 | // MessagePort::New() may return nullptr if execution is terminated | |
| 363 | 371 | // within it. | |
| 364 | 372 | if (child_port != nullptr) | |
| 365 | 373 | env->set_message_port(child_port->object(isolate_)); | |
| 374 | + | ||
| 375 | + return child_port; | ||
| 366 | 376 | } | |
| 367 | 377 | ||
| 368 | 378 | void Worker::JoinThread() { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -70,7 +70,7 @@ class Worker : public AsyncWrap { | |||
| 70 | 70 | static void LoopStartTime(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 71 | 71 | ||
| 72 | 72 | private: | |
| 73 | - void CreateEnvMessagePort(Environment* env); | ||
| 73 | + bool CreateEnvMessagePort(Environment* env); | ||
| 74 | 74 | static size_t NearHeapLimit(void* data, size_t current_heap_limit, | |
| 75 | 75 | size_t initial_heap_limit); | |
| 76 | 76 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,22 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + const { Worker } = require('worker_threads'); | ||
| 5 | + | ||
| 6 | + // Do not use isMainThread so that this test itself can be run inside a Worker. | ||
| 7 | + if (!process.env.HAS_STARTED_WORKER) { | ||
| 8 | + process.env.HAS_STARTED_WORKER = 1; | ||
| 9 | + const opts = { | ||
| 10 | + resourceLimits: { | ||
| 11 | + maxYoungGenerationSizeMb: 0, | ||
| 12 | + maxOldGenerationSizeMb: 0 | ||
| 13 | + } | ||
| 14 | + }; | ||
| 15 | + | ||
| 16 | + const worker = new Worker(__filename, opts); | ||
| 17 | + worker.on('error', common.mustCall((err) => { | ||
| 18 | + assert.strictEqual(err.code, 'ERR_WORKER_OUT_OF_MEMORY'); | ||
| 19 | + })); | ||
| 20 | + } else { | ||
| 21 | + setInterval(() => {}, 1); | ||
| 22 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments