From 927c427cbee33eb8f7f5ace42e572620b0004f1a Mon Sep 17 00:00:00 2001 From: Bence Nagy Date: Tue, 17 Jul 2018 16:06:11 +0200 Subject: [PATCH 1/2] client: Create a new HTTP session for each request The globally shared connection resets after some time. When it's reset, the web worker will optimistically try to use it anyway, and fail with a connection error. WIth many web workers running behind a load balancer, this means that a huge portion of login requests would randomly land on a broken session and it was common for people to need to retry 3-4 times until their login attempt finally worked. You can see here how within the sentry project's own code, sessions are created on demand instead of being shared globally: https://github.com/getsentry/sentry/blob/27cc0fed47732dec907668a4529ca39bb384bf5a/src/sentry/http.py#L271 --- sentry_auth_gitlab/client.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sentry_auth_gitlab/client.py b/sentry_auth_gitlab/client.py index dce93eb..5ab60d6 100644 --- a/sentry_auth_gitlab/client.py +++ b/sentry_auth_gitlab/client.py @@ -14,14 +14,13 @@ def __init__(self, message='', status=None): class GitLabClient(object): - http = http.build_session() - def _request(self, path, access_token): + session = http.build_session() headers = {'Authorization': 'Bearer {0}'.format(access_token)} url = '{0}/{1}'.format(API_BASE_URL, path.lstrip('/')) try: - req = self.http.get(url, headers=headers) + req = session.get(url, headers=headers) except RequestException as e: raise GitLabApiError(unicode(e), status=e.status_code) return json.loads(req.content) From 363f54094849d3b3ee25dad6781dc700bcfcd986 Mon Sep 17 00:00:00 2001 From: Bence Nagy Date: Tue, 17 Jul 2018 16:08:46 +0200 Subject: [PATCH 2/2] client: Fix error when a RequestException has no status_code It's not available for instance for the following RequestException: ConnectionError(ProtocolError('Connection aborted.', error("(104, 'ECONNRESET')",)),) --- sentry_auth_gitlab/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentry_auth_gitlab/client.py b/sentry_auth_gitlab/client.py index 5ab60d6..dbb670f 100644 --- a/sentry_auth_gitlab/client.py +++ b/sentry_auth_gitlab/client.py @@ -22,7 +22,7 @@ def _request(self, path, access_token): try: req = session.get(url, headers=headers) except RequestException as e: - raise GitLabApiError(unicode(e), status=e.status_code) + raise GitLabApiError(unicode(e), status=getattr(e, 'status_code', None)) return json.loads(req.content) def get_user(self, access_token):