Skip to content

Error trying to disconnect #568

@numbereself

Description

@numbereself

When i try calling the async disconnect function as a result of a packet i get an error stating "Cannot write to closing transport"

Here is the code I used:

import socketio
import asyncio

async def main():
  sio = socketio.AsyncClient(logger=True)

  @sio.event
  def connect():
    print('connection established')

  @sio.event
  async def disconnect():
    print('connection closed')

  @sio.event
  async def welcome(data):
    await sio.emit("loaded", {
      "height": 1080,
      "width": 1920,
      "scale": 2,
      "success": 1
    })
    await sio.sleep(1.2)
    await sio.disconnect()

  await sio.connect("wss://eu2.adventure.land:2083")
  await sio.wait()

asyncio.run(main())

And here is the ouput:

PS C:\Users\Gary\Documents\alPaca> py .\test.py
Engine.IO connection established
Namespace / is connected
connection established
Received event "welcome" [/]
Emitting event "loaded" [/]
Received event "entities" [/]
Received event "entities" [/]
Received event "entities" [/]
Received event "entities" [/]
Received event "action" [/]
Received event "hit" [/]
Received event "death" [/]
Engine.IO connection dropped
Received event "entities" [/]
Traceback (most recent call last):
  File ".\test.py", line 29, in <module>
    asyncio.run(main())
  File "C:\Python38\lib\asyncio\runners.py", line 43, in run
  File "C:\Python38\lib\asyncio\base_events.py", line 616, in run_until_complete
    return future.result()
  File ".\test.py", line 27, in main
    await sio.wait()
  File "C:\Python38\lib\site-packages\socketio\asyncio_client.py", line 128, in wait
    await self.eio.wait()
  File "C:\Python38\lib\site-packages\engineio\asyncio_client.py", line 88, in wait
    await self.read_loop_task
  File "C:\Python38\lib\site-packages\engineio\asyncio_client.py", line 526, in _read_loop_websocket
    await self.write_loop_task
  File "C:\Python38\lib\site-packages\engineio\asyncio_client.py", line 597, in _write_loop
    await self.ws.send_str(pkt.encode(
  File "C:\Python38\lib\site-packages\aiohttp\client_ws.py", line 150, in send_str
    await self._writer.send(data, binary=False, compress=compress)
  File "C:\Python38\lib\site-packages\aiohttp\http_websocket.py", line 687, in send
    await self._send_frame(message, WSMsgType.TEXT, compress)
  File "C:\Python38\lib\site-packages\aiohttp\http_websocket.py", line 598, in _send_frame
    raise ConnectionResetError("Cannot write to closing transport")
ConnectionResetError: Cannot write to closing transport
Traceback (most recent call last):
  File "C:\Python38\lib\asyncio\proactor_events.py", line 116, in __del__
  File "C:\Python38\lib\asyncio\proactor_events.py", line 108, in close
  File "C:\Python38\lib\asyncio\base_events.py", line 719, in call_soon
  File "C:\Python38\lib\asyncio\base_events.py", line 508, in _check_closed
RuntimeError: Event loop is closed
PS C:\Users\Gary\Documents\alPaca> pip show python-engineio
Name: python-engineio
Version: 3.13.1
Summary: Engine.IO server
Home-page: http://github.com/miguelgrinberg/python-engineio/
Author: Miguel Grinberg
Author-email: [email protected]
License: MIT
Location: c:\python38\lib\site-packages
Requires: six
Required-by: python-socketio
PS C:\Users\Gary\Documents\alPaca> pip show python-socketio
Name: python-socketio
Version: 4.6.0
Summary: Socket.IO server
Home-page: http://github.com/miguelgrinberg/python-socketio/
Author: Miguel Grinberg
Author-email: [email protected]
License: MIT
Location: c:\python38\lib\site-packages
Requires: python-engineio, six
Required-by:

I am not exactly sure what this server in particular is running, but I am asuming it is NodeJS.
Also I feel like a disconnect event should fire regardless of the reason. No event fires however.
I was expecting to see the disconnect event fire at least. Also not seeing an exception is preferable.
Or is there an issue about using sleep here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions