Comments (12)
Since these retry-able errors happen quite frequently, I'd really like for this to be a feature sooner than later.
Thanks for your efforts!
from python-storage.
We implemented this in production and have seen zero errors after 5 days.
Previously we were seeing ~10 errors a day.
This solved our issues. Thanks @micimize & @pietrodn
def add_client_retries(client):
""" Retry connection to prevent connectionResetError
"""
adapter = requests.adapters.HTTPAdapter(max_retries=5)
client._http.mount("https://", adapter)
client._http._auth_request.session.mount("https://", adapter)
return client
in main.py:
from google.cloud import storage
from google.cloud import bigquery
storage_client = add_client_retries(storage.Client())
bq_client = add_client_retries(bigquery.Client())
Also, remember to only initialize these once outside of your main() function and reuse them in main().
from python-storage.
This is now resolved for storage. Retries are supported by default, documentation work for configuring them is pending (for now, see docstrings).
from python-storage.
@dylancaponi does it work in the same environment without the _http
argument? 401 means unauthorized, so you probably need to "bind the credentials" like the docs say the default does:
If not passed, an
_http
object is created that is bound to thecredentials
for the current object
from python-storage.
They broke the monorepo up, but I found where they set credentials for reference:
if self._http_internal is None:
self._http_internal = google.auth.transport.requests.AuthorizedSession(
self._credentials,
refresh_timeout=_CREDENTIALS_REFRESH_TIMEOUT,
)
from python-storage.
Thanks! I think I want to do something like:
storage_client = storage.Client()
adapter = requests.adapters.HTTPAdapter(max_retries=5)
storage_client._http.mount("https://", adapter)
storage_client._http._auth_request.session.mount("https://", adapter)
as mentioned here:
googleapis/python-bigquery#59 (comment)
After 8 days of testing, this function did not terminate once due to connectionResetError
!
Adding to production code and will report back.
from python-storage.
This might be possible with the gcs client currently via
session = requests.Session()
session.mount("https://storage.googleapis.com", requests.adapters.HTTPAdapter(max_retries=5))
client = Client(project=env.GOOGLE_PROJECT, _http=session)
Haven't tested though
from python-storage.
@micimize This is giving me errors (below) on deployment. Any idea why?
I'm assuming Client here is really:
from google.cloud import storage
storage.Client(...)
?
Code snippet:
from google.cloud import storage
import requests
session = requests.Session()
session.mount("https://storage.googleapis.com", requests.adapters.HTTPAdapter(max_retries=5))
client = storage.Client(project=PROJECT_ID, _http=session)
Error when attempting blob.download_as_string()
:
ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Function failed on loading user code. Error message: 401 GET https://storage.googleapis.com/download/storage/v1/b/<redacted file name>/o/secrets?alt=media: ('Request failed with status code', 401, 'Expected one of', <HTTPStatus.OK: 200>, <HTTPStatus.PARTIAL_CONTENT: 206>)
from python-storage.
@micimize Yes, the code runs when we don't pass _http
. That is how our normal (non-retrying) connection is established.
builtins.storage_client = storage.Client(project='<redacted>')
However, that means it's not passing the session that defines 5 retries which I really want to do. Do you know what the proper approach to that is?
from python-storage.
@dylancaponi I don't, but what I would do is keep digging through the source until you find google.auth.transport.requests.AuthorizedSession
. You basically want to extract the auth logic they're using and figure out how to combine it with the requests.adapters.HTTPAdapter(max_retries=5)
solution, and then pass the resulting session in as _http
from python-storage.
The solution above worked for a month or two but we are now experiencing this issue again ...
How is everyone else faring?
from python-storage.
@andrewsg : What release version of google-cloud-storage
is retries supported by default?
from python-storage.
Related Issues (20)
- tests.system.test_bucket: test_blob_exists_hierarchy failed HOT 1
- tests.system.test_bucket: test_bucket_list_blobs_hierarchy_root_level failed
- tests.system.test_bucket: test_bucket_list_blobs_hierarchy_first_level failed
- tests.system.test_bucket: test_bucket_list_blobs_hierarchy_second_level failed
- tests.system.test_bucket: test_bucket_list_blobs_hierarchy_third_level failed
- tests.system.test_bucket: test_bucket_list_blobs_hierarchy_w_include_trailing_delimiter failed
- tests.system.test_bucket: test_bucket_list_blobs failed HOT 1
- tests.system.test_bucket: test_bucket_list_blobs_w_user_project failed
- tests.system.test_bucket: test_bucket_list_blobs_paginated failed HOT 1
- tests.system.test_bucket: test_bucket_list_blobs_paginated_w_offset failed HOT 1
- tests.system.test_transfer_manager: test_upload_many_skip_if_exists failed HOT 2
- tests.system.test_transfer_manager: test_upload_many_from_filenames_with_attributes failed HOT 1
- tests.system.test_transfer_manager: test_download_many failed HOT 1
- tests.system.test_transfer_manager: test_download_many_with_threads_and_file_objs failed HOT 1
- tests.system.test_bucket: test_ubla_set_unset_preserves_acls failed HOT 1
- tests.system.test_kms_integration: test_bucket_w_default_kms_key_name failed HOT 1
- Make it possible to update / add to the user-agent for an existing client object
- Micropi cannot install the package HOT 1
- OSError occurred while downloading files using transfer_manager.download_many_to_path HOT 6
- Warning: a recent release failed
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-storage.