Problem/Motivation

As noted in https://www.drupal.org/project/drupal/issues/2825358#comment-16832572 Raven's CSP subscriber can lead to an error when CSP module is enabled from within updatedb on a site where Raven is already enabled.

I observed that Google Tag module, which also implements a CspEventSubscriber, did not exhibit the same behaviour, so I'm mostly copying that module's approach.

Steps to reproduce

- Target environment already has Raven enabled
- Deploy will enable CSP module via hook_update_N module enable
- updatedb call will error at completion

PHP Fatal error:  Uncaught Error: Class "Drupal\csp\CspEvents" not found in /app/web/modules/contrib/raven/src/EventSubscriber/CspSubscriber.php:22
The sequence its hitting us is during a deployment.

Pre deployment - we have the raven module enabled - which uses the class exists pattern to provide a CSP subscriber. We do not have the CSP module in place.

In a deployment (where we want to enable the CSP module) we run the update / config on a new image with a new deployment identifier.

As we have a new deployment identifier the container compiles - so calls RegisterEventSubscribersPass processes and calls get subscribed events on the raven event subscriber - as CSP module has not yet been enabled class_exists returns false.

The return of class_exists appears to get cached by Class Loader in missing classes array.

The update then runs and enables the CSP module.

When drupal_flush_all_caches runs and rebuilds the container the new CSP event subscriber is picked up - but due to the previous class exists check the autoloader doesn't return the fill - it throws an error.

[error] Error: Class "Drupal\csp\CspEvents" not found in Drupal\csp\EventSubscriber\SettingsCspSubscriber::getSubscribedEvents() (line 29 of /app/web/modules/contrib/csp/src/EventSubscriber/SettingsCspSubscriber.php)

- https://www.drupal.org/project/drupal/issues/2825358#comment-16832572

Proposed resolution

As shown in Google Tag module, use RavenServiceProvider to provide event listeners only if the required module is present. Code adapted from

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork raven-3635763

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

xurizaemon created an issue. See original summary.

xurizaemon’s picture

Issue summary: View changes
xurizaemon’s picture

Issue summary: View changes
mfb’s picture

Presumably, another workaround would be to have a separate raven_csp integration module that depends on both raven and csp. But this seems like a reasonable workaround if we want everything to just "magically" work via the one module.

  • mfb committed 10c60f6a on 7.x authored by xurizaemon
    fix: #3635763 Fatal error: Class Drupal\csp\CspEvents not found on CSP...
mfb’s picture

Status: Needs review » Fixed

After this merged, I did some further testing I should have done previously - updating Raven module, installing csp, etc. and seems good to go.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.