Skip to content
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

src,worker: add isInternalWorker #56469

Merged
merged 7 commits into from
Jan 14, 2025

Conversation

Ceres6
Copy link
Contributor

@Ceres6 Ceres6 commented Jan 4, 2025

This PR adds an isInternalWorker to node:worker_threads similar to isMainThread but to detect if the thread is an instance of InternalWorker

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Jan 4, 2025
@Ceres6
Copy link
Contributor Author

Ceres6 commented Jan 4, 2025

cc @JakobJingleheimer @bengl

@Ceres6
Copy link
Contributor Author

Ceres6 commented Jan 4, 2025

Might close nodejs/import-in-the-middle/issues/38

Copy link
Member

@JakobJingleheimer JakobJingleheimer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done!

Maaaybe for consistency with isMainThread, the name should actually be isInternalThread (sorry, I was the one who originally told said isInternalWorker).

doc/api/worker_threads.md Outdated Show resolved Hide resolved
doc/api/worker_threads.md Outdated Show resolved Hide resolved
Copy link

codecov bot commented Jan 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.52%. Comparing base (afafee2) to head (10cbd4a).
Report is 77 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #56469      +/-   ##
==========================================
- Coverage   88.53%   88.52%   -0.02%     
==========================================
  Files         657      660       +3     
  Lines      190761   190898     +137     
  Branches    36616    36626      +10     
==========================================
+ Hits       168899   168996      +97     
- Misses      15048    15089      +41     
+ Partials     6814     6813       -1     
Files with missing lines Coverage Δ
lib/internal/worker.js 99.81% <100.00%> (+<0.01%) ⬆️
lib/worker_threads.js 100.00% <100.00%> (ø)
src/node_worker.cc 84.15% <100.00%> (+0.20%) ⬆️
src/node_worker.h 90.90% <100.00%> (+0.90%) ⬆️

... and 43 files with indirect coverage changes

Copy link
Member

@JakobJingleheimer JakobJingleheimer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nearly there! 🙌

lib/worker_threads.js Outdated Show resolved Hide resolved
lib/worker_threads.js Outdated Show resolved Hide resolved
test/parallel/test-is-internal-thread.mjs Outdated Show resolved Hide resolved
test/fixtures/worker-is-internal-thread.js Outdated Show resolved Hide resolved
test/parallel/test-is-internal-thread.mjs Outdated Show resolved Hide resolved
test/parallel/test-is-internal-thread.mjs Outdated Show resolved Hide resolved
test/parallel/test-is-internal-thread.mjs Outdated Show resolved Hide resolved
Copy link
Member

@JakobJingleheimer JakobJingleheimer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 😁 hopefully @bengl can confirm it does what he needs.

@daeyeon daeyeon added semver-minor PRs that contain new features and should be released in the next minor version. author ready PRs that have at least one approval, no pending requests for changes, and a CI started. labels Jan 7, 2025
@Ceres6
Copy link
Contributor Author

Ceres6 commented Jan 13, 2025

Can we move this forward? @JakobJingleheimer
Did you have time to check it? @bengl

@JakobJingleheimer
Copy link
Member

It's all good from my perspective.

But Bryan would be the one to verify that it suits the need. I think I saw from him somewhere that he's been quite overwhelmed recently, which kinda means this is stuck unless we can find someone else who can verify it.

@marco-ippolito marco-ippolito added the request-ci Add this label to start a Jenkins CI on a PR. label Jan 13, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jan 13, 2025
@nodejs-github-bot
Copy link
Collaborator

@JakobJingleheimer JakobJingleheimer removed the needs-ci PRs that need a full CI run. label Jan 13, 2025
@JakobJingleheimer
Copy link
Member

@jsumners-nr, I think this is related to what you do IRL. Is this something you can say will or won't meet the needs of APMs?

@jsumners-nr
Copy link

@jsumners-nr, I think this is related to what you do IRL. Is this something you can say will or won't meet the needs of APMs?

Right now, what I can say is that I recall several discussions around this sort of feature in loader and/or diagnostics conversations. I cannot recall where those discussions are, or really who was participating. I think @Qard was participating and had specific ideas about how this would be useful, but I'm not 100% sure of that.

In my personal APM work, I haven't seen a need to know that it is a new thread. We just, don't deal with threads.

I'm not clear how this would solve the linked IITM issue. That issue seems rooted in ESM (like most of the issues holding that project down).

In short, this seems like a fair feature. But I don't have enough knowledge to provide the information you're looking for.

@JakobJingleheimer
Copy link
Member

The TLDR context was that APMs need a way to know whether they're running inside the loader worker. I can't recall why they need to know that.

@jsumners-nr
Copy link

The TLDR context was that APMs need a way to know whether they're running inside the loader worker. I can't recall why they need to know that.

Yeah, me either 😢

@Qard
Copy link
Member

Qard commented Jan 14, 2025

That should be sufficient. Basically was just needed to logic-branch what was loaded from the library depending on if it's loaded in the app thread or the loader thread. We couldn't identify a loader thread by looking at the workerData object. (At least not reliably as the contents were unspecified.)

I'm not at Datadog anymore so might still want to poke @bengl to verify there's nothing else, but as far as I recall that was it.

@JakobJingleheimer
Copy link
Member

Awesome, thank you!

Copy link
Member

@bengl bengl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, does what I need it to.

@JakobJingleheimer JakobJingleheimer added commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. labels Jan 14, 2025
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Jan 14, 2025
@nodejs-github-bot nodejs-github-bot merged commit 732744c into nodejs:main Jan 14, 2025
73 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in 732744c

@JakobJingleheimer
Copy link
Member

Thanks everyone!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. c++ Issues and PRs that require attention from people who are familiar with C++. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. lib / src Issues and PRs related to general changes in the lib or src directory. semver-minor PRs that contain new features and should be released in the next minor version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants