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 | try: |
|
60 | try: | |
59 | headers = { |
|
61 | response = session.post(url, data=msgpack.packb(payload)) | |
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) |
|
|||
64 | except pycurl.error as e: |
|
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 | msg = '{}. \npycurl traceback: {}'.format(e, traceback.format_exc()) |
|
68 | msg = '{}. \npycurl traceback: {}'.format(e, traceback.format_exc()) | |
66 | raise exceptions.HttpVCSCommunicationError(msg) |
|
69 | raise exceptions.HttpVCSCommunicationError(msg) | |
67 | except Exception as e: |
|
70 | except Exception as e: | |
@@ -80,7 +83,7 b' def _remote_call(url, payload, exception' | |||||
80 | try: |
|
83 | try: | |
81 | response = msgpack.unpackb(response.content, raw=False) |
|
84 | response = msgpack.unpackb(response.content, raw=False) | |
82 | except Exception: |
|
85 | except Exception: | |
83 |
log.exception('Failed to decode response |
|
86 | log.exception('Failed to decode response from msgpack') | |
84 | raise |
|
87 | raise | |
85 |
|
88 | |||
86 | error = response.get('error') |
|
89 | error = response.get('error') | |
@@ -112,6 +115,7 b' def _streaming_remote_call(url, payload,' | |||||
112 | } |
|
115 | } | |
113 | response = session.post(url, data=msgpack.packb(payload), headers=headers) |
|
116 | response = session.post(url, data=msgpack.packb(payload), headers=headers) | |
114 | except pycurl.error as e: |
|
117 | except pycurl.error as e: | |
|
118 | error_code, error_message = e.args | |||
115 | msg = '{}. \npycurl traceback: {}'.format(e, traceback.format_exc()) |
|
119 | msg = '{}. \npycurl traceback: {}'.format(e, traceback.format_exc()) | |
116 | raise exceptions.HttpVCSCommunicationError(msg) |
|
120 | raise exceptions.HttpVCSCommunicationError(msg) | |
117 | except Exception as e: |
|
121 | except Exception as e: | |
@@ -296,8 +300,9 b' class RemoteRepo(object):' | |||||
296 | namespace=self._cache_namespace, condition=cache_on and cache_key) |
|
300 | namespace=self._cache_namespace, condition=cache_on and cache_key) | |
297 | def remote_call(_cache_key): |
|
301 | def remote_call(_cache_key): | |
298 | if self._call_with_logging: |
|
302 | if self._call_with_logging: | |
299 | log.debug('Calling %s@%s with args:%.10240r. wire_context: %s cache_on: %s', |
|
303 | args_repr = f'ARG: {str(args):.256}|KW: {str(kwargs):.256}' | |
300 | url, name, args, context_uid, cache_on) |
|
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 | return _remote_call(url, payload, EXCEPTIONS_MAP, self._session) |
|
306 | return _remote_call(url, payload, EXCEPTIONS_MAP, self._session) | |
302 |
|
307 | |||
303 | result = remote_call(cache_key) |
|
308 | result = remote_call(cache_key) | |
@@ -318,8 +323,9 b' class RemoteRepo(object):' | |||||
318 | # Cache is a problem because this is a stream |
|
323 | # Cache is a problem because this is a stream | |
319 | def streaming_remote_call(_cache_key): |
|
324 | def streaming_remote_call(_cache_key): | |
320 | if self._call_with_logging: |
|
325 | if self._call_with_logging: | |
321 | log.debug('Calling %s@%s with args:%.10240r. wire_context: %s cache_on: %s', |
|
326 | args_repr = f'ARG: {str(args):.256}|KW: {str(kwargs):.256}' | |
322 | url, name, args, context_uid, cache_on) |
|
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 | return _streaming_remote_call(url, payload, EXCEPTIONS_MAP, self._session, self.CHUNK_SIZE) |
|
329 | return _streaming_remote_call(url, payload, EXCEPTIONS_MAP, self._session, self.CHUNK_SIZE) | |
324 |
|
330 | |||
325 | result = streaming_remote_call(cache_key) |
|
331 | result = streaming_remote_call(cache_key) |
General Comments 0
You need to be logged in to leave comments.
Login now