Automattic / jetpack

Security, performance, marketing, and design tools — Jetpack is made by WordPress experts to make WP sites safer and faster, and help you grow your traffic.
https://jetpack.com/
Other
1.59k stars 798 forks source link

Jetpack Autoloader: is loading the corresponding file from a different project which is using a different namespace #22950

Open porter707 opened 2 years ago

porter707 commented 2 years ago

Impacted plugin

Jetpack

Steps to Reproduce

PHP Fatal error: Uncaught Error: Call to undefined function GuzzleHttp\choose_handler()

The autoloader in Jetpack is deciding to load the file from the version of guzzlehttp that's in a different namespace.

This can be reproduced by installing:

UpdraftPlus version 1.22.3 Google Listings and Ads 1.11.1

Install UpdraftPlus and then connect to an S3 remote storage (UpdraftVault or S3) Then install the Google Listings and Ads plugin and navigate to the UpdraftPlus settings page

You get the above error.

It's asked to ensure GuzzleHttp\choose_handler() is available, and it instead loads a file that has Automattic\WooCommerce\GoogleListingsAndAds\Vendor\GuzzleHttp\choose_handler() in it which has the wrong namespace.

The version of GuzzleHttp installed does not matter even with both plugins running version 7 the error happens because of the namespace.

A clear and concise description of what you expected to happen.

No response

What actually happened

No response

Other information

No response

Operating System

macOS, Linux

OS Version

No response

Browser

Firefox

Browser Version(s)

No response

DavidAnderson684 commented 2 years ago

Sorry - correction (my fault for passing on wrong info to porter707) - the two plugins do have different versions of Guzzle (6 and 7). But as far as we can see, that is not related. The code in the Guzzle bundled with our plugin is being used, but in vendor/guzzlehttp/guzzle/src/HandlerStack.php (which has namespace GuzzleHttp;), it calls choose_handler(), but the JetPack autloader responds by requiring a file that is in the Automattic\WooCommerce\GoogleListingsAndAds\Vendor\GuzzleHttp namespace, as described, and this results in the function-not-found fatal error. on that function call.

DavidAnderson684 commented 2 years ago

Don't test on UpdraftPlus 1.22.4 - in that, we have included a work-around by explicitly including guzzlehttp/guzzle/src/functions_include.php to make sure that the functions had been loaded into the GuzzleHttp namespace to avoid the fatal error.

DavidAnderson684 commented 2 years ago

We've also tested changing to Guzzle 7 so that both projects have Guzzle 7 - the same problem still occurs. (We mention this so that you're not misled by the different Guzzle versions in the plugins that can be used for testing mentioned above if you use those).

jeherve commented 2 years ago

This may be something worth reporting to the team working on the Google Listings and Ads plugin. It seemed they had previously added some workarounds for that specific problem: https://github.com/woocommerce/google-listings-and-ads/pull/957

Do you think you could open an issue there, mentioning the version of the Google Listings and Ads plugin you use on the site where you encounter that issue?

Thank you!