BrokenPipeError when using Attached Service Account on GCE Instance
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 35/100
- Tipo de issue
- Bug
- Clareza
- Razoavelmente clara
- Status de atividade
- Estagnada
- Stack de tecnologia
- google-cloud, python
- Domínio
- api, authentication, cloud
Direção de pesquisa
Comece por google_auth_httplib2.py e google/auth/compute_engine/_metadata.py no caminho de atualização do token mostrado pelo traceback. Reproduza o problema em uma instância GCE após a expiração das credenciais ao fazer uma chamada à Drive API e, em seguida, verifique se a atualização e a solicitação de API subsequente são concluídas sem BrokenPipeError.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Environment details
- OS type and version: Google Compute Engine (GCE) with Container-Optimized OS
- Python version:
Python 3.7.16 - pip version:
pip 21.3.1 google-api-python-client== 1.12.8google-auth==1.35.0google-auth-httplib2==0.2.0
Steps to reproduce
- Deploy a Python application on a GCE instance with an attached service account.
- Use
google.auth.default()for authentication. - Let the service run for a few hours to allow the token to expire.
- Perform a Google Drive API call during token refresh (e.g., listing files or creating a folder).
Code example
gdrive_credentials: Credentials = (
Credentials.from_service_account_info(
gcp_credentials_dict,
scopes=SCOPES,
)
if gcp_credentials_dict
else google.auth.default(scopes=SCOPES)[0]
)
def create_services(credentials, scopes):
drive_service = build(
"drive", "v3", credentials=credentials
)
docs_service = build(
"docs", "v1", credentials=credentials
)
return credentials, drive_service, docs_service
def get_or_create_folder(self, drive_service, folder_name):
"""
Checks if a folder exists in the root directory and creates it if not.
:param drive_service: Authorized Drive API client.
:param folder_name: The name of the folder to check or create.
:return: The folder ID.
"""
# Search for the folder in the root directory
query = f"name = '{folder_name}' and mimeType = 'application/vnd.google-apps.folder' and 'root' in parents and trashed = false"
response = (
drive_service.files().list(q=query, fields="files(id, name)").execute()
)
files = response.get("files", [])
if files:
# Folder exists, return its ID
return files[0]["id"]
else:
# Folder doesn't exist, create it
folder_metadata = {
"name": folder_name,
"mimeType": "application/vnd.google-apps.folder",
"parents": ["root"], # Place in the root directory
}
folder = (
drive_service.files()
.create(body=folder_metadata, fields="id")
.execute()
)
return folder["id"]
Stacktrace
BrokenPipeError: [Errno 32] Broken pipe
File "/app/endpoints/webhooks.py", line 292, in get_services_status
current_app.config.get("BUILD_ENVIRONMENT"),
File "/app/middleware/gdocsprinter.py", line 43, in print_file_with_template
template_id, gdocs_drive_service, replace_template, build_environment
File "/app/middleware/gdocsprinter.py", line 111, in create_template_copy
drive_service, f"{build_environment}-prints"
File "/app/middleware/gdocsprinter.py", line 86, in get_or_create_folder
drive_service.files().list(q=query, fields="files(id, name)").execute()
File "googleapiclient/_helpers.py", line 134, in positional_wrapper
return wrapped(*args, **kwargs)
File "googleapiclient/http.py", line 909, in execute
headers=self.headers,
File "googleapiclient/http.py", line 204, in _retry_request
raise exception
File "googleapiclient/http.py", line 177, in _retry_request
resp, content = http.request(uri, method, *args, **kwargs)
File "google_auth_httplib2.py", line 190, in request
self._request, method, uri, request_headers)
File "/usr/local/lib/python3.7/site-packages/google/auth/credentials.py", line 133, in before_request
self.refresh(request)
File "/usr/local/lib/python3.7/site-packages/google/auth/compute_engine/credentials.py", line 111, in refresh
self._retrieve_info(request)
File "/usr/local/lib/python3.7/site-packages/google/auth/compute_engine/credentials.py", line 88, in _retrieve_info
request, service_account=self._service_account_email
File "/usr/local/lib/python3.7/site-packages/google/auth/compute_engine/_metadata.py", line 234, in get_service_account_info
return get(request, path, params={"recursive": "true"})
File "/usr/local/lib/python3.7/site-packages/google/auth/compute_engine/_metadata.py", line 150, in get
response = request(url=url, method="GET", headers=_METADATA_HEADERS)
File "google_auth_httplib2.py", line 117, in __call__
url, method=method, body=body, headers=headers, **kwargs)
File "__init__.py", line 1709, in request
conn, authority, uri, request_uri, method, body, headers, redirections, cachekey,
File "__init__.py", line 1424, in _request
(response, content) = self._conn_request(conn, request_uri, method, body, headers)
File "__init__.py", line 1347, in _conn_request
conn.request(method, request_uri, body, headers)
File "http/client.py", line 1281, in request
self._send_request(method, url, body, headers, encode_chunked)
File "http/client.py", line 1327, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "http/client.py", line 1276, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "http/client.py", line 1036, in _send_output
self.send(msg)
File "http/client.py", line 997, in send
self.sock.sendall(data)
Brief summary
After switching the authentication method for our application from service account keys to an attached service account on a Google Compute Engine (GCE) instance, we are encountering a BrokenPipeError during API calls to Google Drive.
The issue only occurs during token refresh after the application has been running for a couple of hours. Following the first failure, the service works again without intervention.
Thanks
- Linguagem predominante
- Python
- Estrelas
- 8.9k
- Forks
- 2.6k
- Merge médio
- 9h 58min
- PRs com merge (30d)
- 6
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de googleapis/google-api-python-client
-
Disable prettyPrint by default for Google Sheets API responsesTalvez já em andamento @pawciobiel assumiu há 63 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
googleapis/google-api-python-client#2788 ·
Mantenedores costumam responder em até 1 dia
-
test: connection leak test test_discovery_http_is_closed is shadowed and syntactically invalidTalvez já em andamento @Capstan assumiu há 138 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
googleapis/google-api-python-client#2757 ·
Mantenedores costumam responder em até 1 dia
-
test: strict positional parameter enforcement is ignored under pytestTalvez já em andamento @Capstan assumiu há 138 dias. Aberta
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 92/100
googleapis/google-api-python-client#2755 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 35/100
googleapis/google-api-python-client#2825 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Option to skip per-method docstring generation in build() (memory / high-concurrency)Talvez já em andamento @rootkiller6788 assumiu há 25 dias. Aberta
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 52/100
googleapis/google-api-python-client#2779 ·
Mantenedores costumam responder em até 1 dia
Todas as issues de googleapis/google-api-python-client
Issues semelhantes
-
area:core-platform effort:S priority:P3 status:in-review type:test
Dificuldade 2/5 Menos de uma hora Facilidade para iniciantes 80/100
randomparity/kdive#3246 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Requantification library converts m/z to mass with the hydrogen-atom mass instead of the proton massAbertabug
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 85/100
nf-core/metaboigniter#130 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
common-workflow-language/cwl-utils#477 ·
Mantenedores costumam responder em até 1 dia
-
Add dependabotAbertafeat
Dificuldade 2/5 Menos de uma hora Facilidade para iniciantes 72/100
open-nudge/opentemplate#204 ·
Mantenedores costumam responder em até 1 dia
-
github-stale-ci-pr-closer: KV state is double-wrapped, never persists, and hits the depth-32 limitTalvez já em andamento @VascoSch92 assumiu hoje. Abertapriority:medium ready-for-dev
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
OpenHands/extensions#781 ·
Mantenedores costumam responder em até 1 dia