Skip to content

Commit 1df84da

Browse files
committed
added SSE total and socket read timeouts
1 parent 485bb49 commit 1df84da

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

splitio/push/sse.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
SSE_EVENT_MESSAGE = 'message'
1414
_DEFAULT_HEADERS = {'accept': 'text/event-stream'}
1515
_EVENT_SEPARATORS = set([b'\n', b'\r\n'])
16-
_DEFAULT_ASYNC_TIMEOUT = 300
16+
_DEFAULT_SOCKET_READ_TIMEOUT = 70
1717

1818
SSEEvent = namedtuple('SSEEvent', ['event_id', 'event', 'retry', 'data'])
1919

@@ -139,7 +139,7 @@ def shutdown(self):
139139
class SSEClientAsync(object):
140140
"""SSE Client implementation."""
141141

142-
def __init__(self, timeout=_DEFAULT_ASYNC_TIMEOUT):
142+
def __init__(self, socket_read_timeout=_DEFAULT_SOCKET_READ_TIMEOUT):
143143
"""
144144
Construct an SSE client.
145145
@@ -152,7 +152,7 @@ def __init__(self, timeout=_DEFAULT_ASYNC_TIMEOUT):
152152
:param timeout: connection & read timeout
153153
:type timeout: float
154154
"""
155-
self._timeout = timeout
155+
self._socket_read_timeout = socket_read_timeout + socket_read_timeout * .3
156156
self._response = None
157157
self._done = asyncio.Event()
158158

@@ -168,7 +168,8 @@ async def start(self, url, extra_headers=None): # pylint:disable=protected-acce
168168
raise RuntimeError('Client already started.')
169169

170170
self._done.clear()
171-
async with aiohttp.ClientSession() as sess:
171+
client_timeout = aiohttp.ClientTimeout(total=0, sock_read=self._socket_read_timeout)
172+
async with aiohttp.ClientSession(timeout=client_timeout) as sess:
172173
try:
173174
async with sess.get(url, headers=get_headers(extra_headers)) as response:
174175
self._response = response

0 commit comments

Comments
 (0)