Conflict with PHP8.3 and gRPC Extension

Created on 12 May 2025, 3 months ago

Problem/Motivation

Periodically running into this error:

The website encountered an unexpected error. Try again later.  
  
_Error_: Maximum call stack size of 10436608 bytes (zend.max_allowed_stack_size - zend.reserved_stack_size) reached. Infinite recursion? in _Google\ApiCore\CredentialsWrapper->Google\ApiCore\{closure}()_ (line _244_ of _/var/www/html/vendor/google/gax/src/CredentialsWrapper.php_).

The error appears to be related to: https://www.php.net/manual/en/migration83.incompatible.php; a backword incompatible change to version 8.3 of PHP:

Programs that were very close to overflowing the call stack may now throw an Error when using more than zend.max_allowed_stack_size-zend.reserved_stack_size bytes of stack (fiber.stack_size-zend.reserved_stack_size for fibers).

Steps to reproduce

Perform a search on a custom Vertex AI Search page on a Drupal site that is hosted in an environment where the gRPC PHP extension (version 1.68+) is installed and the version of PHP is 8.3+.

The search will error out, but upon refresh or two, the search will complete.

Essentially, the gRPC transport is not working with PHP8.3 and the 1.68+ gRPC extension.

Proposed resolution

Ideally a fix needs to happen in the gRPC PHP extension.
Various workaround have been proposed.

  1. Set the value of the new PHP directive (zend.max_allowed_stack_size) to -1. This will disable the stack size check.
  2. Use a try/catch around the problem code in the module (this is happening when making a request. Within the catch, retry the request until it succeeds without error.

The zend.max_allowed_stack_size is a System scope directive and can't be changed at runtime. Getting access to setting it in some environments could be difficult. Even if possible, the stack size check is being turned off.

The try/catch seems reasonable, however the retry-until-succeeds seems a bit hacky and this approach removes the performance benefit of using gRPC transport over REST.

Another approach is to provide control over which transport to use (REST or gRPC). If no transport is explicitly set when creating a Service Client (such as the Search Service Client provided by the Google Cloud Discovery client library) then gRPC will be used if it is available. In the case here, the gRPC extension is found and the gRPC Transport is attempted, and the error occurs. Using REST as a transport gets around this problem.

Having the option to specify REST vs gRPC is a good feature to have regardless of the existing bug. In the short term, it can be set to REST to circumvent any errors.

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States tzura

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024