-
Notifications
You must be signed in to change notification settings - Fork 3.9k
node:worker_threads low-hanging fruit #18758
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…rowing synchronously" This reverts commit 1448e6a.
…ference to GlobalObject
src/bun_js.zig
Outdated
| .args = ctx.args, | ||
| .graph = graph_ptr, | ||
| .is_main_thread = true, | ||
| .destruct_main_thread_on_exit = bun.getenvTruthy("BUN_DESTRUCT_VM_ON_EXIT"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| .destruct_main_thread_on_exit = bun.getenvTruthy("BUN_DESTRUCT_VM_ON_EXIT"), | |
| .destruct_main_thread_on_exit = bun.getRuntimeFeatureFlag("BUN_DESTRUCT_VM_ON_EXIT"), |
Jarred-Sumner
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly looks good but a few comments
| auto* globalObject = defaultGlobalObject(lexicalGlobalObject); | ||
| if (globalObject && callback.isCallable()) { | ||
| if (auto* process = jsDynamicCast<Bun::Process*>(globalObject->processObject())) { | ||
| process->queueNextTick(globalObject, AsyncContextFrame::withAsyncContextIfNeeded(globalObject, callback)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you check when Node calls this callback? It's unlikely called on process.nextTick
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They attach it to the message port to be called later. I didn't look very hard into where it gets called from there; I'll undo the change for now and investigate more for a later PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#18768 is where the fixed version of this will go
This reverts commits: - 92a73de Move napiEnvs to ScriptExecutionContext and give napi_env a strong reference to GlobalObject - a0e41dc Add test for #18139 - 806b59c Test napi_add_finalizer in main thread instead of worker - 110f398 Emit online event before Worker entrypoint runs - 6943c56 Accept callback in MessagePort.close These are being moved to new PRs.
What does this PR do?
Fixes some of the easier tests from test/parallel/test-worker-*
execArgv: []receives an empty array forprocess.execArgvinstead of inheriting the parent thread's array (I haven't found this covered in the Node tests yet so I added it to ours)Progress toward Bun crash with Worker #18139 (but not fixed; I may move that to another PR if I get a complete fix in)BUN_DESTRUCT_VM_ON_EXIT=1, which tells Bun to destroy the main thread's JavaScript VM when the process exits. Normally, Worker VMs are the only ones that get destroyed. The intent of this flag is that running a test or program with it will expose bugs that would otherwise only have occurred if the code was running inside a Worker that exited. For instance, the changes from Fix UDPSocket not being closed when VM destructs #18687 were motivated by running a Node UDP test withBUN_DESTRUCT_VM_ON_EXIT=1.node:fs/promisesFileHandleconstructor beFileHandleinstead ofFileHandle2, and adds a propertySymbol(messaging_transfer_symbol)(this is progress towardstest-worker-message-port-transfer-fake-js-transferable-internal.jsbut does not fix it just yet)postMessageavoid calling a user-overriddenArray.prototype[Symbol.iterator]autoSelectFamilyAttemptTimeoutDefaultin node:net unique per-thread. Our code doesn't use this value anywhere, but Node's test harness multiplies the value by a fixed amount before the tests run. This means that if you have a Node test that repeatedly spawns new Workers, each one will greatly increase the globalautoSelectFamilyAttemptTimeoutDefault, until eventually aTypeErroris thrown because the harness attempts to increase it past the u32 limit.worker.getHeapSnapshot()error if called on a Worker that isn't running or if the options object is invalidMakes theonlineevent fire right before a Worker starts running its entrypoint instead of right afterexitevent is fired with code 1 instead of 0 on a Worker which throws an uncaught exceptionworker.terminate, and emit a deprecation warning if you do soSymbolarguments passed in theargvandexecArgvarrays coerce toSymbol(description)instead of throwing an errorprocess.argvcontain[worker eval]instead of a Blob URL for Workers spawned witheval: trueenvoption spawning a Worker is not the right typeMessagePort, and makesMessagePort.closeaccept a callbackeval: trueWorkersTODOs:
terminatedoesn't fire theexitevent (this affects several tests)How did you verify your code works?
Node tests