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

DebugSubscriber - Fix activation check #24554

Merged
merged 1 commit into from
Sep 19, 2022
Merged

Conversation

totten
Copy link
Member

@totten totten commented Sep 18, 2022

Overview

This component injects debug info about API calls. It only does so if XDebug is configured with the suitable mode (ie xdebug.mode=develop or XDEBUG_MODE=develop)

This requires a guard based on XDebug configuration. This guard is slightly wrong, which can sometimes raise spurious errors.

The key thing is that XDebug reads configuration from multiple sources (eg php.ini or env-var). A recent buildkit update relied on env-var working (civicrm/civicrm-buildkit#727).

Before

The guard only consults ini_get('xdebug.mode'). If an env-var exists (eg XDEBUG_MODE), then ini_get() does not correctly reveal the effective policy.

This sometimes leads to failures like this (where in xdebug.mode looked like it had develop enabled, but XDEBUG_MODE actually disabled it, so anything that relies on develop mode fails):

1) api_v3_ACLCachingTest::testActivityCreateCustomBefore with data set "APIv3" (3)
Failure in api call for custom_field getoptions:  Function must be enabled in php.ini by setting 'xdebug.mode' to 'develop'
#0 [internal function]: PHPUnit\Util\ErrorHandler->__invoke(2, 'Function must b...', '/home/jenkins/b...', 99)
#1 /home/jenkins/bknix-max/build/delme-2-2/web/sites/all/modules/civicrm/Civi/API/Subscriber/DebugSubscriber.php(99): xdebug_time_index()
#2 /home/jenkins/bknix-max/build/delme-2-2/web/sites/all/modules/civicrm/vendor/symfony/event-dispatcher/EventDispatcher.php(264): Civi\API\Subscriber\DebugSubscriber->onApiRespond(Object(Civi\API\Event\RespondEvent), 'civi.api.respon...',

After

The guard works with both php.ini's xdebug.mode and env-var XDEBUG_MODE. It does this by asking XDebug for the effective mode (rather than looking at specific config flags).

Technical Details

See also: https://xdebug.org/docs/all_functions#xdebug_info

The option will behave correctly on XDebug 3.1+. On 3.0, it falls back to the older (less-accurate) check. All the systems I care about have 3.1.+

This subscriber only interjects if XDebug is configured with the suitable mode.

To see if the mode is suitable, it consults `ini_get("xdebug.mode")`, but
this is not quite right -- because the mode may be set other ways (eg
`XDEBUG_MODE`). In XDebug 3.1+, you can get the true effective-mode
by calling `xdebug_info`.

See also: https://xdebug.org/docs/all_functions#xdebug_info
@civibot
Copy link

civibot bot commented Sep 18, 2022

(Standard links)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants