googleapis / google-cloud-php

Google Cloud Client Library for PHP
https://cloud.google.com/php/docs/reference
Apache License 2.0
1.09k stars 433 forks source link

Cloud Logging fatal error when using gRPC transport in AppEngine Standard for PHP 7.4 #3616

Closed javiermarinros closed 10 months ago

javiermarinros commented 3 years ago

Using Cloud Logging with gRPC transport automatically kills the instance and a 502 Bad Gateway message is shown to the user under AppEngine Standard for PHP 7.4

This log is written:

WARNING: [pool app] child 19 exited on signal 11 (SIGSEGV) after 6.307432 seconds from start [error] 23#23: *6 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: ..., server: , request: "GET /?transport=grpc HTTP/1.1", upstream: "fastcgi://unix:/tmp/google-config/php-fpm.sock:", host: "...."

Steps to reproduce

composer.json

{
  "name": "gae-test",
  "require": {
    "google/cloud-logging": "^v1.21.0"
  }
}

app.yaml

runtime: php74
service: gae-test

entrypoint: serve app.php

handlers:
  - url: .*
    script: auto

app.php

<?php

use Google\Cloud\Logging\Logger;
use Google\Cloud\Logging\LoggingClient;

require 'vendor/autoload.php';

LoggingClient::psrBatchLogger(
    'app',
    [
        'clientConfig' => [
            'projectId' => $_SERVER['GOOGLE_CLOUD_PROJECT'],
            'transport' => $_GET['transport'] ?? 'grpc',
        ]
    ]
)->log(Logger::WARNING, 'Message');

echo 'Done!';

php.ini

extension=grpc.so
extension=protobuf.so

Testing with param ?transport=rest is working fine, ?transport=grpc fails.

javiermarinros commented 3 years ago

It looks certain methods, like listTasks, from Google Cloud Tasks library are not working either when PHP GRPC extension is enabled.

ajupazhamayil commented 11 months ago

Sorry for the late reply and thank you for raising the issue. The above code is working for me with a different setup. Since this issue is really old, could you please confirm its still happening for you? If not, will close by end of week.

javiermarinros commented 11 months ago

I have just tried to enable the GRPC extension on an running AppEngine PHP 8.1 instance, and I got this error for every request:

Request was aborted after waiting too long to attempt to service your request.

So, for now, I will stick to REST transport that has been working just fine for several years.

ajupazhamayil commented 11 months ago

Interesting, may I ask the google-cloud-php version you are using?

javiermarinros commented 11 months ago

Sure, we are using:

{ "google/cloud-storage": "^v1.33.2", "google/cloud-logging": "^v1.28.1", "google/cloud-tasks": "^v1.13.1", "google/cloud-pubsub": "^v1.46.2", "google/cloud-secret-manager": "^v1.12.2", "google/cloud-translate": "^v1.15.1" }

ajupazhamayil commented 10 months ago

To try this in AppEngine, I have made the following setup.

runtime: php81

php.ini

extension=grpc.so
extension=protobuf.so

home.php (Used the app code from https://github.com/crazyrov/gcp_appengine_php_demo)

<?php
    require_once __DIR__ . '/vendor/autoload.php';
    use Google\Cloud\Logging\Logger;
    use Google\Cloud\Logging\LoggingClient;
    use Google\Cloud\Datastore\DatastoreClient;

    LoggingClient::psrBatchLogger(
    'app',
    [
        'clientConfig' => [
            'projectId' => 'myProjectId',
            'transport' => 'grpc'
        ]
    ])->log(Logger::WARNING, 'Message');
    echo 'Done';

composer.json

{
    "require": {
        "google/cloud-datastore": "^1.2",
    "google/cloud-logging": "^v1.28.1"
    }
}

Result Got the warning in the Google Cloud Logs:

insertId: "myInsertId"
jsonPayload: {
message: "Message"
}
labels: {1}
logName: "projects/myProjectId/logs/app"
receiveTimestamp: "2023-11-04T07:06:15.054059348Z"
resource: {2}
severity: "WARNING"
timestamp: "2023-11-04T07:06:14.682943Z"
trace: "projects/myProjectId/traces/traceId"
}

I am unable to reproduce the 502 issue here!

ajupazhamayil commented 10 months ago

Hi @javiermarinros, If not reproducible, I will need to close this as it is running in both my Linux and AppEngine.

javiermarinros commented 10 months ago

Hi @ajupazhamayil the test project I created is working fine under PHP 8.1. However, when I activate the "grpc.so" extension in a project in production and with a lot of traffic, I do get the errors I mentioned above.

ajupazhamayil commented 10 months ago

Could you please provide me a specific traffic level (requests per second or something in the similar lines)? I will try to generate that amount of traffic in my application to replicate the issue.

javiermarinros commented 10 months ago

We have an average of 150-200 request per second Instances-–-App-Engine-–-Biwenger-–-Google-Cloud-console

ajupazhamayil commented 10 months ago

Hi @javiermarinros, I tried with AppEngine for a 200+ request per second and every request came back 200 OK! Seems like the reproduction is hard!

Screenshot 2023-11-10 at 18 37 55
javiermarinros commented 10 months ago

Hi @ajupazhamayil, yes, it is a difficult error to reproduce. As I said, as long as I don't enable the grpc.so extension in the php.ini file, all works as expected, so I will stick to that for now. Besides that, I found out that using Google libraries with the GRPC protocol sometimes breaks UTF encoding with special characters like Emoji, something that with REST doesn't happen. Thank you for your help.

ajupazhamayil commented 10 months ago

Thank you for the prompt replies. Will close this bug as not reproducible.

Also, raised a bug to gRPC repo to see if we can get some action on your issue: https://github.com/grpc/grpc/issues/34958

Thank you!