GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Use of Batch adds duplicate, redundant gcloud-python/x.xx.x to User-Agent header in an unbounded fashion · Issue #565 · googleapis/python-storage

This repository was archived by the owner on Mar 31, 2026. It is now read-only.
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

Use of Batch adds duplicate, redundant gcloud-python/x.xx.x to User-Agent header in an unbounded fashion #565

Copy link
Copy link
Closed
#570
Closed
Use of Batch adds duplicate, redundant gcloud-python/x.xx.x to User-Agent header in an unbounded fashion#565
#570
Copy link
Assignees
ddelgrosso1
Labels
api: storageIssues related to the googleapis/python-storage API.priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Description

@michio-nikaido
michio-nikaido
opened on Aug 31, 2021
Issue body actions

Overview

We first became aware of this issue when we began seeing "Error 413 (Request Entity Too Large)" responses to a variety of GCS requests after we implemented blob.reload() calls in a Batch context. We discovered after capturing the HTTP requests that the User-Agent headers for both the "outer" batch request and the contained requests were all filled with hundreds of 'gcloud-python/1.40.0' specifications. For example, we've seen a single batch request containing 51 reload requests with each User-Agent specification containing over 100 repetitions of 'gcloud-python/1.40.0'. Overall, this request had 5,300 occurrences of the same 'gcloud-python/1.40.0'

Analysis

When batch calls are made, a ' gcloud-python/x.xx.x ' is blindly appended to the underlying connection's _client_info.user_agent string:

https://github.com/googleapis/python-storage/blob/master/google/cloud/storage/_http.py#L59

As a result, successive batch calls result in the connection._client_info.user-agent string accumulating more and more, duplicate ' gcloud-python/x.xx.x ' specifications. If a Client object continues making batch requests, the user-agent property continues to grow without limit.

Environment details

  • OS type and version: Ubuntu 20.04
  • Python version: 3.7.11
  • pip version: 21.2.4
  • google-cloud-storage version: 1.42.0

Repro Script

from google.api_core import exceptions as g_exc
from google.cloud.storage.blob import Blob
from google.cloud.storage.client import Client

project = '<GCP PROJCT NAME>'
bucket_name = '<GCS BUCKET NAME>'

# Client.__init__ initializes self._connection which initiallizes a Connection object as defined in
# google.cloud.storage._http.py which automatically appends a 'gcloud-python/x.xx.x' spec to the
# the user_agent property
c = Client(project=project)
print(c._connection._client_info.user_agent)

bucket = c.get_bucket(bucket_name)
blobs = list(c.list_blobs(bucket))[:1]

# ----- First batch call adds duplicate user_agent spec
print("Before batch: "  + c._connection._client_info.user_agent)

try:
    # Creation of a Batch object results in another call which again appends another (duplicate) 
    # 'gcloud-python/x.xx.x' to the user_agent property.
    with c.batch()as batch:
        print("Batch context: " + batch._client_info.user_agent)
        for blob in blobs:
            blob.reload()
except g_exc.NotFound:
    pass
print("After batch: "  + c._connection._client_info.user_agent)

# ----- Subsequent batch calls continue to add more duplicates ad nauseam
for i in range(5):
    try:
        with c.batch()as batch:
            print(f"Iteration {i} - Batch context: " + batch._client_info.user_agent)
            for blob in blobs:
                blob.reload()
    except g_exc.NotFound:
        pass

Repro instructions

  1. Modify repro script to specify valid 'project' and 'bucket_name' values
  2. Execute script

Activity

  1. product-auto-label
    added
    api: storageIssues related to the googleapis/python-storage API.
    on Aug 31, 2021
  2. ddelgrosso1
    added
    priority: p2Moderately-important priority. Fix may not be included in next release.
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    on Aug 31, 2021
  3. ddelgrosso1
    self-assigned this
    on Sep 1, 2021
  4. andrewsg
    added
    priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.
    on Sep 1, 2021
  5. andrewsg commented on Sep 1, 2021

    @andrewsg
    andrewsg
    on Sep 1, 2021
    Contributor
    More actions

    This is related to an ongoing outage. Upgrading to P1. I will review PR and advise. Thanks Denis!

  6. gcf-merge-on-green
    closed this as completedin #570on Sep 2, 2021
  7. gcf-merge-on-green
    added a commit that references this issue on Sep 2, 2021

    fix: do not append duplicates to user agent string (#570)

    This issue will close once commit 57cf3a1 is merged into the 'main' branch.
    57cf3a1
  8. cojenco
    added 2 commits that reference this issue on Oct 13, 2021

    fix: do not append duplicates to user agent string (googleapis#570)

    This issue will close once commit c38c495 is merged into the 'main' branch.
    c38c495

    fix: do not append duplicates to user agent string (googleapis#570)

    This issue will close once commit 6978d2e is merged into the 'main' branch.
    6978d2e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @ddelgrosso1
    ddelgrosso1

Labels

api: storageIssues related to the googleapis/python-storage API.priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.