Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: work around segfault with >100 jobs in google life sciences backend #1451

Merged
merged 7 commits into from Mar 4, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 22 additions & 5 deletions snakemake/executors/google_lifesciences.py
Expand Up @@ -22,6 +22,8 @@
from snakemake.executors import ClusterExecutor, sleep
from snakemake.common import get_container_image, get_file_hash
from snakemake.resources import DefaultResources
import httplib2
import google_auth_httplib2
cademirch marked this conversation as resolved.
Show resolved Hide resolved

# https://github.com/googleapis/google-api-python-client/issues/299#issuecomment-343255309
logging.getLogger("googleapiclient.discovery_cache").setLevel(logging.ERROR)
Expand Down Expand Up @@ -148,6 +150,7 @@ def _get_services(self):
# Credentials must be exported to environment
try:
creds = GoogleCredentials.get_application_default()
self.creds = creds
except ApplicationDefaultCredentialsError as ex:
log_verbose_traceback(ex)
raise ex
Expand Down Expand Up @@ -885,7 +888,7 @@ def _job_was_successful(self, status):

return success

def _retry_request(self, request, timeout=2, attempts=3):
def _retry_request(self, request, http=None, timeout=2, attempts=3):
"""The Google Python API client frequently has BrokenPipe errors. This
function takes a request, and executes it up to number of retry,
each time with a 2* increase in timeout.
Expand All @@ -897,24 +900,38 @@ def _retry_request(self, request, timeout=2, attempts=3):
attempts: remaining attempts, throw error when hit 0
"""
import googleapiclient
import google.auth

credentials, project_id = google.auth.default(
scopes=["https://www.googleapis.com/auth/cloud-platform"]
)
if http is None:
http = google_auth_httplib2.AuthorizedHttp(
credentials=credentials, http=httplib2.Http()
)
try:
return request.execute()
return request.execute(http=http)
except BrokenPipeError as ex:
if attempts > 0:
time.sleep(timeout)
return self._retry_request(request, timeout * 2, attempts - 1)
return self._retry_request(
request, http=http, timeout=timeout * 2, attempts=attempts - 1
)
raise ex
except googleapiclient.errors.HttpError as ex:
if attempts > 0:
time.sleep(timeout)
return self._retry_request(request, timeout * 2, attempts - 1)
return self._retry_request(
request, http=http, timeout=timeout * 2, attempts=attempts - 1
)
log_verbose_traceback(ex)
raise ex
except Exception as ex:
if attempts > 0:
time.sleep(timeout)
return self._retry_request(request, timeout * 2, attempts - 1)
return self._retry_request(
request, http=http, timeout=timeout * 2, attempts=attempts - 1
)
log_verbose_traceback(ex)
raise ex

Expand Down