-
Notifications
You must be signed in to change notification settings - Fork 8
agents: add runtime control for asset collection #377
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
Open
santigimeno
wants to merge
1
commit into
node-v22.x-nsolid-v6.x
Choose a base branch
from
santi/assets_enabled
base: node-v22.x-nsolid-v6.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🧩 Analysis chain
*Critical: data race on assets_enabled_ (and on config_ for contCpuProfile) when called from _from_js.
start_*_from_js invokes do_start_prof_init on potentially non‑agent threads. Reading a non‑atomic bool and nlohmann::json without synchronization is undefined behavior.
Fix options (pick one):
Minimal atomic fix (recommended now), plus JSON type safety:
Header changes (agents/grpc/src/grpc_agent.h):
Update config() to snapshot contCpuProfile to atomic:
Optional: if assetsEnabled should also suppress continuous profiles, add a fast check at the start of got_continuous_profile to drop or close streams when disabled.
🏁 Script executed:
Length of output: 17670
I need to inspect the actual implementation of
do_start_prof_initand check the current state of the code:Now let me inspect the actual implementation in grpc_agent.cc to see the current state:
Let me now examine the actual implementation in the grpc_agent.cc file around the line numbers indicated:
[/run_scripts]
🏁 Script executed:
Length of output: 1197
Now let me check the header file to see the current declarations:
[/run_scripts]
🏁 Script executed:
Length of output: 279
Let me check the config() method and how config_ is synchronized:
[/run_scripts]
🏁 Script executed:
Length of output: 182
Let me find what method contains the config assignment and check for synchronization:
[/run_scripts]
🏁 Script executed:
Length of output: 1735
Let me verify one more detail about whether config() can be called concurrently with do_start_prof_init by checking the call sites:
[/run_scripts]
🏁 Script executed:
Length of output: 0
Let me try a broader search for how config_msg_cb_ is used:
[/run_scripts]
🏁 Script executed:
Length of output: 1111
Critical data race confirmed: unprotected config_ access from concurrent threads.
The code modification at line 2097 (
if (!assets_enabled_)) exposes a classic data race:config_msg_cb_(agent event loop thread) writesconfig_unsafely at line 1019 viaconfig()methoddo_start_prof_init(arbitrary thread via *_from_js V8 callbacks) readsconfig_unsafely at lines 2110–2115Additionally,
assets_enabled_is declaredstd::atomic<bool>but uses implicitoperator!conversion instead of explicit.load(std::memory_order_acquire), bypassing memory ordering guarantees.Fix as suggested in the review comment:
if (!assets_enabled_)withif (!assets_enabled_.load(std::memory_order_acquire))std::atomic<bool> cont_cpu_profile_enabled_{false}to headercontCpuProfilefromconfig_into the atomic in theconfig()method (with proper null/type checks)cont_cpu_profile_enabled_.load(std::memory_order_acquire)in the check at line 2110–2115These changes eliminate the data race by preventing unprotected JSON reads from arbitrary threads.
🤖 Prompt for AI Agents