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

Mark config as immutable and interned to avoid refcounting race conditions #2516

Merged
merged 3 commits into from
Feb 15, 2024

Conversation

bwoebi
Copy link
Collaborator

@bwoebi bwoebi commented Feb 12, 2024

Description

Multiple threads manipulating the refcount at once is a possible source of race conditions (especially with many small requests increasing the likeness).

Properly mark the strings as interned / arrays as immutable to avoid this.

Reviewer checklist

  • Test coverage seems ok.
  • Appropriate labels assigned.

…tions

Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>
Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>
Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>
@bwoebi bwoebi requested review from a team as code owners February 12, 2024 13:42
@realFlowControl realFlowControl added profiling Relates to the Continuous Profiler tracing labels Feb 12, 2024
static void zai_config_intern_zval(zval *pzval) {
if (Z_TYPE_P(pzval) == IS_STRING) {
#if PHP_VERSION_ID >= 70400
ZVAL_INTERNED_STR(pzval, zend_new_interned_string(Z_STR_P(pzval)));
Copy link
Collaborator

Choose a reason for hiding this comment

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

During a request, zend_new_interned_string will store strings in an arena in CG(interned_strings) (well, at least on PHP 8.3). Is that long enough for the values being store during zai_config_first_time_rinit? I worry that it's not.

Copy link
Collaborator Author

@bwoebi bwoebi Feb 13, 2024

Choose a reason for hiding this comment

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

That's why there's a zend_interned_strings_switch_storage call in zai_config_first_rinit, so that it'll actually store it in persistent storage.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, I missed that. Thanks!

@bwoebi bwoebi merged commit 8f21029 into master Feb 15, 2024
624 checks passed
@bwoebi bwoebi deleted the bob/immutable-config branch February 15, 2024 16:21
@github-actions github-actions bot added this to the 0.98.0 milestone Feb 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
profiling Relates to the Continuous Profiler tracing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants