@@ -46,6 +46,7 @@ def __init__(
46
46
auth : Optional [BasicAuth ] = None ,
47
47
ssl : Union [SSLContext , bool , Fingerprint ] = False ,
48
48
timeout : Optional [int ] = None ,
49
+ ssl_close_timeout : Optional [Union [int , float ]] = 10 ,
49
50
client_session_args : Optional [Dict [str , Any ]] = None ,
50
51
) -> None :
51
52
"""Initialize the transport with the given aiohttp parameters.
@@ -55,6 +56,8 @@ def __init__(
55
56
:param cookies: Dict of HTTP cookies.
56
57
:param auth: BasicAuth object to enable Basic HTTP auth if needed
57
58
:param ssl: ssl_context of the connection. Use ssl=False to disable encryption
59
+ :param ssl_close_timeout: Timeout in seconds to wait for the ssl connection
60
+ to close properly
58
61
:param client_session_args: Dict of extra args passed to
59
62
`aiohttp.ClientSession`_
60
63
@@ -67,6 +70,7 @@ def __init__(
67
70
self .auth : Optional [BasicAuth ] = auth
68
71
self .ssl : Union [SSLContext , bool , Fingerprint ] = ssl
69
72
self .timeout : Optional [int ] = timeout
73
+ self .ssl_close_timeout : Optional [Union [int , float ]] = ssl_close_timeout
70
74
self .client_session_args = client_session_args
71
75
self .session : Optional [aiohttp .ClientSession ] = None
72
76
@@ -165,7 +169,10 @@ async def close(self) -> None:
165
169
if self .session is not None :
166
170
closed_event = self .create_aiohttp_closed_event (self .session )
167
171
await self .session .close ()
168
- await closed_event .wait ()
172
+ try :
173
+ await asyncio .wait_for (closed_event .wait (), self .ssl_close_timeout )
174
+ except asyncio .TimeoutError :
175
+ pass
169
176
self .session = None
170
177
171
178
async def execute (
0 commit comments