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

fix(prof): crash on PHP 8.4 #3019

Merged
merged 6 commits into from
Jan 7, 2025
Merged

fix(prof): crash on PHP 8.4 #3019

merged 6 commits into from
Jan 7, 2025

Conversation

morrisonlevi
Copy link
Collaborator

@morrisonlevi morrisonlevi commented Jan 7, 2025

Description

Fixes #3012. The profiler may crash when:

  • The profiler is enabled
  • And the application is on PHP 8.4
  • And the application is using a web SAPI (the CLI does not use the component which causes the crash)

Note that for a variety of reasons, applications do not seem to crash as often as you might expect when reading the cause below as well as the attached patch. Nonetheless, every application which meets these conditions should upgrade to v1.6.0 or newer.

Cause and Fix

The cause is from a change in PHP 8.4 that was missed. The internals upgrading guide says:

* zend_get_internal_function_extension_handle[s]() must now be used over
  zend_get_op_array_extension_handle[s]() when registering run_time_cache slots
  for internal functions. If you need a cache slot for both internal and user
  functions, you may obtain a slot for each through the corresponding function.

This run_time_cache_slot is used while walking the call stack in the profiler. So if the profiler takes a sample when an internal function is on the call stack, then it will use an op_array_extension_handle instead of the internal_function_extension_handle. The fix is to call zend_get_internal_function_extension_handle as well and use that handle instead of the user handle when accessing the run time cache for internal functions.

Reviewer checklist

  • Test coverage seems ok.
  • Appropriate labels assigned.

@morrisonlevi morrisonlevi added cat:app-crash profiling Relates to the Continuous Profiler labels Jan 7, 2025
@morrisonlevi morrisonlevi requested review from a team as code owners January 7, 2025 07:28
@codecov-commenter
Copy link

codecov-commenter commented Jan 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.80%. Comparing base (906cbc5) to head (5e6e8ca).
Report is 3 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #3019   +/-   ##
=========================================
  Coverage     74.80%   74.80%           
  Complexity     2781     2781           
=========================================
  Files           112      112           
  Lines         11017    11017           
=========================================
  Hits           8241     8241           
  Misses         2776     2776           
Flag Coverage Δ
tracer-php 74.80% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 906cbc5...5e6e8ca. Read the comment docs.

@pr-commenter
Copy link

pr-commenter bot commented Jan 7, 2025

Benchmarks [ profiler ]

Benchmark execution time: 2025-01-07 16:39:18

Comparing candidate commit 5e6e8ca in PR branch levi/prof-debug with baseline commit 906cbc5 in branch master.

Found 2 performance improvements and 0 performance regressions! Performance is the same for 26 metrics, 8 unstable metrics.

scenario:php-profiler-exceptions-control

  • 🟩 cpu_user_time [-6.999ms; -1.831ms] or [-13.328%; -3.486%]

scenario:walk_stack/1

  • 🟩 wall_time [-270.516ns; -265.408ns] or [-2.178%; -2.137%]

#if PHP_VERSION_ID >= 80400
// On PHP 8.4+, the internal cache slots need to be registered separately
// from the user ones.
_internal_run_time_cache_handle =
zend_get_op_array_extension_handles(module_name, 2);
Copy link
Collaborator

Choose a reason for hiding this comment

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

You meant to call zend_get_internal_function_extension_handle here? You're calling op_array again.

@morrisonlevi morrisonlevi merged commit 8d0cf27 into master Jan 7, 2025
706 of 734 checks passed
@morrisonlevi morrisonlevi deleted the levi/prof-debug branch January 7, 2025 18:43
@github-actions github-actions bot added this to the 1.6.0 milestone Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cat:app-crash profiling Relates to the Continuous Profiler
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Segfault when profiling is enabled in php 8.4.1 on Ubuntu
4 participants