Skip to content

Commit 7523107

Browse files
authored
Merge pull request #183 from oeway/increase-timeout
Capture request timeout error and increase the timeout value
2 parents d97223c + 47bc01e commit 7523107

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

jupyter_server_proxy/handlers.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,22 @@ async def proxy(self, host, port, proxied_path):
220220
client = httpclient.AsyncHTTPClient()
221221

222222
req = self._build_proxy_request(host, port, proxied_path, body)
223-
response = await client.fetch(req, raise_error=False)
223+
224+
try:
225+
response = await client.fetch(req, raise_error=False)
226+
except httpclient.HTTPError as err:
227+
# We need to capture the timeout error even with raise_error=False,
228+
# because it only affects the HTTPError raised when a non-200 response
229+
# code is used, instead of suppressing all errors.
230+
# Ref: https://www.tornadoweb.org/en/stable/httpclient.html#tornado.httpclient.AsyncHTTPClient.fetch
231+
if err.code == 599:
232+
self._record_activity()
233+
self.set_status(599)
234+
self.write(str(err))
235+
return
236+
else:
237+
raise
238+
224239
# record activity at start and end of requests
225240
self._record_activity()
226241

@@ -315,7 +330,7 @@ def proxy_request_headers(self):
315330
def proxy_request_options(self):
316331
'''A dictionary of options to be used when constructing
317332
a tornado.httpclient.HTTPRequest instance for the proxy request.'''
318-
return dict(follow_redirects=False)
333+
return dict(follow_redirects=False, connect_timeout=250.0, request_timeout=300.0)
319334

320335
def check_xsrf_cookie(self):
321336
'''

0 commit comments

Comments
 (0)