Skip to content

Commit efce226

Browse files
authored
Close http session when bot closes.
This fixes an asyncio error about an unclosed session (eventually resulting in an attribute error): ``` Unclosed client session client_session: <aiohttp.client.ClientSession object at 0x0000023BE9D55040> Unclosed connector connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x0000023BE934B460>, 511380.203)]'] connector: <aiohttp.connector.TCPConnector object at 0x0000023BE9D55610> Fatal error on SSL transport protocol: <asyncio.sslproto.SSLProtocol object at 0x0000023BE87CCF40> transport: <_ProactorSocketTransport fd=-1 read=<_OverlappedFuture cancelled>> Traceback (most recent call last): File "D:\programs\Python39\lib\asyncio\sslproto.py", line 684, in _process_write_backlog self._transport.write(chunk) File "D:\programs\Python39\lib\asyncio\proactor_events.py", line 359, in write self._loop_writing(data=bytes(data)) File "D:\programs\Python39\lib\asyncio\proactor_events.py", line 395, in _loop_writing self._write_fut = self._loop._proactor.send(self._sock, data) AttributeError: 'NoneType' object has no attribute 'send' ```
1 parent d247213 commit efce226

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

twitchio/websocket.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,5 +483,8 @@ async def _close(self):
483483
for fut in futures:
484484
fut.cancel()
485485

486-
await self._websocket.close()
486+
if self._websocket:
487+
await self._websocket.close()
488+
if self._client._http.session:
489+
await self._client._http.session.close()
487490
self._loop.stop()

0 commit comments

Comments
 (0)