|
@@ -40,8 +40,9 @@ from ycmd.responses import ServerError, UnknownExtraConf
|
|
|
|
|
|
_HEADERS = {'content-type': 'application/json'}
|
|
|
_EXECUTOR = UnsafeThreadPoolExecutor( max_workers = 30 )
|
|
|
+_CONNECT_TIMEOUT_SEC = 0.01
|
|
|
# Setting this to None seems to screw up the Requests/urllib3 libs.
|
|
|
-_DEFAULT_TIMEOUT_SEC = 30
|
|
|
+_READ_TIMEOUT_SEC = 30
|
|
|
_HMAC_HEADER = 'x-ycm-hmac'
|
|
|
_logger = logging.getLogger( __name__ )
|
|
|
|
|
@@ -67,7 +68,7 @@ class BaseRequest( object ):
|
|
|
# |timeout| is num seconds to tolerate no response from server before giving
|
|
|
# up; see Requests docs for details (we just pass the param along).
|
|
|
@staticmethod
|
|
|
- def GetDataFromHandler( handler, timeout = _DEFAULT_TIMEOUT_SEC ):
|
|
|
+ def GetDataFromHandler( handler, timeout = _READ_TIMEOUT_SEC ):
|
|
|
return JsonFromFuture( BaseRequest._TalkToHandlerAsync( '',
|
|
|
handler,
|
|
|
'GET',
|
|
@@ -78,7 +79,7 @@ class BaseRequest( object ):
|
|
|
# |timeout| is num seconds to tolerate no response from server before giving
|
|
|
# up; see Requests docs for details (we just pass the param along).
|
|
|
@staticmethod
|
|
|
- def PostDataToHandler( data, handler, timeout = _DEFAULT_TIMEOUT_SEC ):
|
|
|
+ def PostDataToHandler( data, handler, timeout = _READ_TIMEOUT_SEC ):
|
|
|
return JsonFromFuture( BaseRequest.PostDataToHandlerAsync( data,
|
|
|
handler,
|
|
|
timeout ) )
|
|
@@ -88,7 +89,7 @@ class BaseRequest( object ):
|
|
|
# |timeout| is num seconds to tolerate no response from server before giving
|
|
|
# up; see Requests docs for details (we just pass the param along).
|
|
|
@staticmethod
|
|
|
- def PostDataToHandlerAsync( data, handler, timeout = _DEFAULT_TIMEOUT_SEC ):
|
|
|
+ def PostDataToHandlerAsync( data, handler, timeout = _READ_TIMEOUT_SEC ):
|
|
|
return BaseRequest._TalkToHandlerAsync( data, handler, 'POST', timeout )
|
|
|
|
|
|
|
|
@@ -100,7 +101,7 @@ class BaseRequest( object ):
|
|
|
def _TalkToHandlerAsync( data,
|
|
|
handler,
|
|
|
method,
|
|
|
- timeout = _DEFAULT_TIMEOUT_SEC ):
|
|
|
+ timeout = _READ_TIMEOUT_SEC ):
|
|
|
def SendRequest( data, handler, method, timeout ):
|
|
|
request_uri = _BuildUri( handler )
|
|
|
if method == 'POST':
|
|
@@ -111,12 +112,12 @@ class BaseRequest( object ):
|
|
|
headers = BaseRequest._ExtraHeaders( method,
|
|
|
request_uri,
|
|
|
sent_data ),
|
|
|
- timeout = timeout )
|
|
|
+ timeout = ( _CONNECT_TIMEOUT_SEC, timeout ) )
|
|
|
if method == 'GET':
|
|
|
return BaseRequest.session.get(
|
|
|
request_uri,
|
|
|
headers = BaseRequest._ExtraHeaders( method, request_uri ),
|
|
|
- timeout = timeout )
|
|
|
+ timeout = ( _CONNECT_TIMEOUT_SEC, timeout ) )
|
|
|
|
|
|
@retries( 5, delay = 0.5, backoff = 1.5 )
|
|
|
def DelayedSendRequest( data, handler, method ):
|
|
@@ -222,6 +223,11 @@ def HandleServerException( display = True, truncate = False ):
|
|
|
_LoadExtraConfFile( e.extra_conf_file )
|
|
|
else:
|
|
|
_IgnoreExtraConfFile( e.extra_conf_file )
|
|
|
+ except requests.exceptions.ConnectTimeout:
|
|
|
+ # We don't display this exception to the user since it is likely to happen
|
|
|
+ # for each subsequent request (typically if the server crashed) and we
|
|
|
+ # don't want to spam the user with it.
|
|
|
+ _logger.exception( 'Unable to connect to server' )
|
|
|
except Exception as e:
|
|
|
_logger.exception( 'Error while handling server response' )
|
|
|
if display:
|