##// END OF EJS Templates
remote-call: added retries for connection-reset-by-peer and optimize logging leaking too much info
super-admin -
r5033:65a0999f default
parent child Browse files
Show More
@@ -54,23 +54,26 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 try:
58
59 headers = {
59 for attempt in range(retries):
60 'X-RC-Method': payload.get('method'),
60 try:
61 'X-RC-Repo-Name': payload.get('_repo_name')
61 response = session.post(url, data=msgpack.packb(payload))
62 }
62 except pycurl.error as e:
63 response = session.post(url, data=msgpack.packb(payload), headers=headers)
63 error_code, error_message = e.args
64 except pycurl.error as e:
64 if error_code == pycurl.E_RECV_ERROR:
65 msg = '{}. \npycurl traceback: {}'.format(e, traceback.format_exc())
65 log.warning(f'Received a "Connection reset by peer" error. '
66 raise exceptions.HttpVCSCommunicationError(msg)
66 f'Retrying... ({attempt + 1}/{retries})')
67 except Exception as e:
67 continue # Retry if connection reset error.
68 message = getattr(e, 'message', '')
68 msg = '{}. \npycurl traceback: {}'.format(e, traceback.format_exc())
69 if 'Failed to connect' in message:
69 raise exceptions.HttpVCSCommunicationError(msg)
70 # gevent doesn't return proper pycurl errors
70 except Exception as e:
71 raise exceptions.HttpVCSCommunicationError(e)
71 message = getattr(e, 'message', '')
72 else:
72 if 'Failed to connect' in message:
73 raise
73 # gevent doesn't return proper pycurl errors
74 raise exceptions.HttpVCSCommunicationError(e)
75 else:
76 raise
74
77
75 if response.status_code >= 400:
78 if response.status_code >= 400:
76 log.error('Call to %s returned non 200 HTTP code: %s',
79 log.error('Call to %s returned non 200 HTTP code: %s',
@@ -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 %r', response.content)
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