Skip to content

Commit f875500

Browse files
authored
Tune session timeouts (#76)
* async client is set to less than server max idle * sync client retries on bad conn (dns lookup, idle timeout, etc.), never on request
1 parent 8055f47 commit f875500

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

stream_chat/async_chat/client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ def __init__(self, api_key, api_secret, timeout=6.0, **options):
3030
super().__init__(
3131
api_key=api_key, api_secret=api_secret, timeout=timeout, **options
3232
)
33-
self.session = aiohttp.ClientSession()
33+
self.session = aiohttp.ClientSession(
34+
connector=aiohttp.TCPConnector(keepalive_timeout=3.9)
35+
)
3436

3537
async def _parse_response(self, response):
3638
text = await response.text()

stream_chat/client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ def __init__(self, api_key, api_secret, timeout=6.0, **options):
2929
super().__init__(
3030
api_key=api_key, api_secret=api_secret, timeout=timeout, **options
3131
)
32-
self.session = requests.Session()
32+
s = requests.Session()
33+
s.mount("http://", requests.adapters.HTTPAdapter(max_retries=1))
34+
s.mount("https://", requests.adapters.HTTPAdapter(max_retries=1))
35+
self.session = s
3336

3437
def _parse_response(self, response):
3538
try:

0 commit comments

Comments
 (0)