Skip to content

Fix outdated files being loaded #1066

@felixarntz

Description

@felixarntz

Bug Description

In the past few days, several fatal errors were reported in the plugin repository:

Each of them points to code locations that are not actually relevant for version 1.2.0, so I'm not quite sure what was causing it, whether it was just a partially failed download - which I cannot imagine, especially given that this was just now reported 3 times in a short period.

@swissspidy mentioned that there can be potential issues on upgrade as a result of using file_exists() checks (see ampproject/amp-wp#2670). We're using the function twice in our plugin code (in loader.php), and we should be able to eliminate the need for them. Given the error messages from the three support tickets, I don't think this is the actual problem here, but it's still something worth improving.

A more likely cause could be that OpCache is not properly reset and does not detect the updated files, so that it partially loads old files (see WP core ticket https://core.trac.wordpress.org/ticket/36455).

Let's explore this a bit further and according fixes.


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

  • There should be no file_exists() checks in loader.php:
    • The one in autoload_classes() should simply be removed because that classmap should only include classes for files that exist.
    • In order to remove the one in autoload_vendor_files(), we need to fix how we generate the third-party/vendor/autoload_files.php file. At the moment, it is simply copied from the main Composer output (done in composer.json), which results in it including also dependencies that are only relevant for development. Let's implement it in a way that only the three files relevant for production are included.
  • opcache_reset() should be called (if available) after Site Kit has been updated (see https://core.trac.wordpress.org/attachment/ticket/36455/36455.5.diff for possible approach).

Implementation Brief

  • Remove file_exists() condition in \Google\Site_Kit\autoload_classes()
  • Remove file_exists() condition in \Google\Site_Kit\autoload_vendor_files()
  • Add @composer dump-autoload --no-dev as a step between @autoload-third-party and copying autoload_files.php in the prefix-dependencies Composer script
    • This results in the autoload_files.php containing an array of only the 3 files needed
    • We don't load the main vendor/autoload.php so this shouldn't affect anything else
  • Add a new googlesitekit_opcache_reset function in the plugin's entrypoint file

Changelog entry

Metadata

Metadata

Assignees

No one assigned

    Labels

    P0High priorityType: BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions