protobuf icon indicating copy to clipboard operation
protobuf copied to clipboard

Fail to push limit

Open rovo79 opened this issue 2 years ago • 13 comments

What version of protobuf and what language are you using? Version: ?? (not sure, on composer install, google/protobuf v3.21.10 showed in logs)

Language: PHP 7.4.33

What operating system (Linux, Windows, ...) and version? Linux, nginx/1.21.6

What runtime / compiler are you using (e.g., python version or gcc version) Composer installed from google/protobuf

What did you do? Steps to reproduce the behavior: Composer install google/cloud and google/protobuf Create PHP app client to authenticate with Google Cloud API services

What did you expect to see On my local machine development environment, this PHP App Client works as intended and returns the requested data from google api.

What did you see instead? On my cloud host environment, receiving a Fail to push limit. I've read about the ways the files may not have been transferred as binaries and altering their line endings. I'm not sure that applies here since this project is composer managed; I'm not pushing the protobuf (or any other third party vendor libraries) to the hosting environment. Make sure you include information that can help us debug (full error message, exception listing, stack trace, logs).

Anything else we should know about your project / environment My local environment is a docker container configured to mirror the hosting environment.

Error message is indicating line 340 in the pushLimit function , but seems to get hung up in the readTag function.

The website encountered an unexpected error. Please try again later.

Google\Protobuf\Internal\GPBDecodeException: Error occurred during parsing: Fail to push limit. in Google\Protobuf\Internal\CodedInputStream->pushLimit() (line 340 of /code/vendor/google/protobuf/src/Google/Protobuf/Internal/CodedInputStream.php).

Google\Protobuf\Internal\CodedInputStream->incrementRecursionDepthAndPushLimit(7471, 0, 0) (Line: 286)
Google\Protobuf\Internal\GPBWire::readMessage(Object, Object) (Line: 435)
Google\Protobuf\Internal\Message::parseFieldFromStreamNoTag(Object, Object, Object) (Line: 515)
Google\Protobuf\Internal\Message->parseFieldFromStream(10, Object, Object) (Line: 811)
Google\Protobuf\Internal\Message->parseFromStream(Object) (Line: 775)
Google\Protobuf\Internal\Message->mergeFromString('') (Line: 61)
Google\Protobuf\Internal\DescriptorPool->internalAddGeneratedFile('', 1) (Line: 288)
GPBMetadata\Google\Analytics\Data\V1Beta\Data::initOnce() (Line: 71)
Google\Analytics\Data\V1beta\DateRange->__construct(Array) (Line: 92)
Drupal\google_analytics_data_api\Controller\GoogleAnalyticsClientController->runReport()
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 564)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 169)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 50)
Drupal\ban\BanMiddleware->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 709)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

rovo79 avatar Dec 08 '22 12:12 rovo79

hi @rovo79 , did you solved your problem? I have same issue when use the google analytic: "google/analytics-data": "^0.8.4" with Acquia hosting and still not find out way to fix it.

flashvnn avatar Jan 31 '23 05:01 flashvnn

@flashvnn I have not found a solution. Ended up stepping back from google analytics as our solution.

rovo79 avatar Jan 31 '23 14:01 rovo79

I am having a similar issue with a PHP site using this library and have determined the source of the problem is the data passed to protobuf from analytics-data/metadata/V1Beta/Data.php. In short, during the build process this file gets altered so that some of the bytes get trimmed, which results in protobuf/src/Google/Protobuf/Internal/CodedInputStream::pushLimit() throwing an exception because this test fails: $byte_limit <= $this->current_limit - $current_position

This might be something outside the scope of this library. @rovo79 do you know how your code gets pushed up to the cloud? It seems that this is actually being altered in GitLab before it gets to our cloud environment, so I am wondering if there is a similar cause for your case.

wantell avatar Mar 30 '23 16:03 wantell

I think the point of protobuf is to generate the code on your server.

I've abandoned pursuing google cloud data for my project.

rovo79 avatar Mar 30 '23 17:03 rovo79

I have been working with others on this problem and have found a work around - you can find my Drupal specific solution here.

The summary is that this and other Google PHP packages have compiled PHP code in a file with a PHP file extension. Look at this file for instance. The Special characters in text files can cause problems when committing te library with Git.

Not all users of PHP libraries deploy them directly, the platform I work with takes a composer.json file and , builds the code base for the website and commits it to a Git repository, then checks out that commit on the servers. Committing the files to Git is what causes the problem as we get this warning when adding the files to the repository

warning: CRLF will be replaced by LF in vendor/google/analytics-data/metadata/V1Beta/Data.php. This changing of the CRLF to LF characters in compiled code is what causes the problem, changing the file and making the file stop working as expected.

We ended up adding a vendor/google/.gitattributes file with

vendor/google/** -text diff to the build script to prevent Git from trying to change the file names.

Drupal specifically comes with a .gitattributes file listing PHP files as text

*.php text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=2 diff=php linguist-language=php unfortunately as there are several packages provided by Google which contain these *.php files with compiled code the solution was to tell Git in the .gitattributes file to treat all files provided by Google (in vendor/google) as non-text (binary).

jrglasgow avatar Apr 07 '23 16:04 jrglasgow

In my case I removed vendor and node_module and then I reinstalled it.

developertugrul avatar Dec 25 '23 12:12 developertugrul

Solution from @jiulongw doesn't work for me for the Drupal site. The platform I work with has vendor folder in .gitignore list. Pipeline builds the composer packages and deploys to Acquia hosting.

gauravmanerkar avatar Jan 22 '24 04:01 gauravmanerkar

Solution from @jiulongw doesn't work for me for the Drupal site. The platform I work with has vendor folder in .gitignore list. Pipeline builds the composer packages and deploys to Acquia hosting.

I'm not sure who you are referring to in your edited comment. I do see in the emails generated on each edit of your comment that you mentioned @jrglasgow and I will state that the solution he stated is working for our site.

To better clarify his fix:

  1. In your composer.json, you need to allow and configure the drupal/core-composer-scaffold plugin
  2. In the composer's "scripts" entry you will need to have a "post-drupal-scaffold-cmd" entry and add this script to create the .gitattributes file: "echo '** -text diff' >> vendor/google/.gitattributes"

As an example, your composer should have something like this:

  "scripts": {
      "post-drupal-scaffold-cmd": [
          "echo '** -text diff' >> vendor/google/.gitattributes"
      ]
  }

wantell avatar Jan 22 '24 20:01 wantell

Thanks @wantell for sharing the detailed steps but looks like in my case i need to fix other dependent packages as well.

gauravmanerkar avatar Jan 23 '24 02:01 gauravmanerkar

@gauravmanerkar the above approach from jrglasgow and wantell is great, but I ended up with a slight variation that ultimately worked for me. Incase it helps out your scenario. In the site root -> private folder, created a google folder; created a file in that folder, google.gitattritubtes. Content of google.attributes = ** -text diff.

Skeleton of reference to Drupal-scaffold file-mapping between vendor/google and private/google :

"drupal-scaffold": {
            "allowed-packages": [
            ],
            "locations": {
                "web-root": "./web"
            },
            "file-mapping": {
                "[project-root]/.editorconfig": false,
                "[project-root]/.gitattributes": false,
                "[project-root]/vendor/google/.gitattributes": "private/google/google.gitattributes"
            }
        },

rovo79 avatar Jan 23 '24 03:01 rovo79

I also have open-telemetry/gen-otlp-protobuf package as dependency which contains similar compiled PHP code. Adding .gitattributes file to both packages solves the problem for me.

    "scripts": {
        "post-drupal-scaffold-cmd": [
          "echo '*.php -text diff' >> vendor/google/.gitattributes",
          "echo '*.php -text diff' >> vendor/open-telemetry/.gitattributes"
        ]
    }

gauravmanerkar avatar Jan 23 '24 03:01 gauravmanerkar

Should a simple .gitattributes file be added to https://github.com/protocolbuffers/protobuf-php to fix this for all the people checking the vendor folder into their git repos?

trackleft avatar Apr 18 '24 18:04 trackleft

FYI on pantheon all of these echo scripts append *.php -text diff to vendor/google/.gitattributes during each composer build making the .gitattributes file grow indefinitely within the artifact repository lol.

See #16572 for possible solution?

trackleft avatar May 07 '24 19:05 trackleft

I also have open-telemetry/gen-otlp-protobuf package as dependency which contains similar compiled PHP code. Adding .gitattributes file to both packages solves the problem for me.

    "scripts": {
        "post-drupal-scaffold-cmd": [
          "echo '*.php -text diff' >> vendor/google/.gitattributes",
          "echo '*.php -text diff' >> vendor/open-telemetry/.gitattributes"
        ]
    }

Replace >> by > to avoid appending new lines during each build.

    "scripts": {
        "post-drupal-scaffold-cmd": [
          "echo '*.php -text diff' > vendor/google/.gitattributes",
          "echo '*.php -text diff' > vendor/open-telemetry/.gitattributes"
        ]
    }

igorbarato avatar Jun 11 '24 03:06 igorbarato