Show More
@@ -54,14 +54,17 b' EXCEPTIONS_MAP = {' | |||
|
54 | 54 | } |
|
55 | 55 | |
|
56 | 56 | |
|
57 | def _remote_call(url, payload, exceptions_map, session): | |
|
57 | def _remote_call(url, payload, exceptions_map, session, retries=3): | |
|
58 | ||
|
59 | for attempt in range(retries): | |
|
58 | 60 | try: |
|
59 | headers = { | |
|
60 | 'X-RC-Method': payload.get('method'), | |
|
61 | 'X-RC-Repo-Name': payload.get('_repo_name') | |
|
62 | } | |
|
63 | response = session.post(url, data=msgpack.packb(payload), headers=headers) | |
|
61 | response = session.post(url, data=msgpack.packb(payload)) | |
|
64 | 62 | except pycurl.error as e: |
|
63 | error_code, error_message = e.args | |
|
64 | if error_code == pycurl.E_RECV_ERROR: | |
|
65 | log.warning(f'Received a "Connection reset by peer" error. ' | |
|
66 | f'Retrying... ({attempt + 1}/{retries})') | |
|
67 | continue # Retry if connection reset error. | |
|
65 | 68 | msg = '{}. \npycurl traceback: {}'.format(e, traceback.format_exc()) |
|
66 | 69 | raise exceptions.HttpVCSCommunicationError(msg) |
|
67 | 70 | except Exception as e: |
@@ -80,7 +83,7 b' def _remote_call(url, payload, exception' | |||
|
80 | 83 | try: |
|
81 | 84 | response = msgpack.unpackb(response.content, raw=False) |
|
82 | 85 | except Exception: |
|
83 |
log.exception('Failed to decode response |
|
|
86 | log.exception('Failed to decode response from msgpack') | |
|
84 | 87 | raise |
|
85 | 88 | |
|
86 | 89 | error = response.get('error') |
@@ -112,6 +115,7 b' def _streaming_remote_call(url, payload,' | |||
|
112 | 115 | } |
|
113 | 116 | response = session.post(url, data=msgpack.packb(payload), headers=headers) |
|
114 | 117 | except pycurl.error as e: |
|
118 | error_code, error_message = e.args | |
|
115 | 119 | msg = '{}. \npycurl traceback: {}'.format(e, traceback.format_exc()) |
|
116 | 120 | raise exceptions.HttpVCSCommunicationError(msg) |
|
117 | 121 | except Exception as e: |
@@ -296,8 +300,9 b' class RemoteRepo(object):' | |||
|
296 | 300 | namespace=self._cache_namespace, condition=cache_on and cache_key) |
|
297 | 301 | def remote_call(_cache_key): |
|
298 | 302 | if self._call_with_logging: |
|
299 | log.debug('Calling %s@%s with args:%.10240r. wire_context: %s cache_on: %s', | |
|
300 | url, name, args, context_uid, cache_on) | |
|
303 | args_repr = f'ARG: {str(args):.256}|KW: {str(kwargs):.256}' | |
|
304 | log.debug('Calling %s@%s with args:%r. wire_context: %s cache_on: %s', | |
|
305 | url, name, args_repr, context_uid, cache_on) | |
|
301 | 306 | return _remote_call(url, payload, EXCEPTIONS_MAP, self._session) |
|
302 | 307 | |
|
303 | 308 | result = remote_call(cache_key) |
@@ -318,8 +323,9 b' class RemoteRepo(object):' | |||
|
318 | 323 | # Cache is a problem because this is a stream |
|
319 | 324 | def streaming_remote_call(_cache_key): |
|
320 | 325 | if self._call_with_logging: |
|
321 | log.debug('Calling %s@%s with args:%.10240r. wire_context: %s cache_on: %s', | |
|
322 | url, name, args, context_uid, cache_on) | |
|
326 | args_repr = f'ARG: {str(args):.256}|KW: {str(kwargs):.256}' | |
|
327 | log.debug('Calling %s@%s with args:%r. wire_context: %s cache_on: %s', | |
|
328 | url, name, args_repr, context_uid, cache_on) | |
|
323 | 329 | return _streaming_remote_call(url, payload, EXCEPTIONS_MAP, self._session, self.CHUNK_SIZE) |
|
324 | 330 | |
|
325 | 331 | result = streaming_remote_call(cache_key) |
General Comments 0
You need to be logged in to leave comments.
Login now