Teekeks / pyTwitchAPI

A Python 3.7 compatible implementation of the Twitch API, EventSub, PubSub and Chat
https://pytwitchapi.dev
MIT License
254 stars 38 forks source link

ConnectionResetError when sending a chat message on closed socket #185

Closed aw-was-here closed 1 year ago

aw-was-here commented 1 year ago

As discussed on Discord, if the app sends a chat message while pyTwitchAPI is in recovery mode, send_message will stack trace with ConnectResetError. Relevant part of the stack trace:

...
  File "/Users/aw/Src/whats-now-playing/nowplaying/twitch/chat.py", line 368, in _post_template
    await self.chat.send_message(
  File "/Users/aw/wnpvenv/lib/python3.10/site-packages/twitchAPI/chat.py", line 799, in send_message
    await self._send_message(f'PRIVMSG {room} :{text}')
  File "/Users/aw/wnpvenv/lib/python3.10/site-packages/twitchAPI/chat.py", line 612, in _send_message
    await self.__connection.send_str(message)
  File "/Users/aw/wnpvenv/lib/python3.10/site-packages/aiohttp/client_ws.py", line 151, in send_str
    await self._writer.send(data, binary=False, compress=compress)
  File "/Users/aw/wnpvenv/lib/python3.10/site-packages/aiohttp/http_websocket.py", line 690, in send
    await self._send_frame(message, WSMsgType.TEXT, compress)
  File "/Users/aw/wnpvenv/lib/python3.10/site-packages/aiohttp/http_websocket.py", line 601, in _send_frame
    raise ConnectionResetError("Cannot write to closing transport")
ConnectionResetError: Cannot write to closing transport
Teekeks commented 1 year ago

Should be addressed by 1ebaeebe8cbffe90efe99be19bc35db44352b189