Skip to content

trio.ClosedResourceError when trying to use simple server example #134

Closed

Description

@danlkv

Hello!

what I do

I use simple server example from here https://trio-websocket.readthedocs.io/en/stable/servers.html
and try to test how fast can it get. I use server code from that page just with added print line.

in one console I do python test_server.py

In another console (2) i do yes | pv | websocat ws://localhost:8000 >dev/null

where websocat is a handy cli tool for websocket https://github.com/vi/websocat.

what I get

I successfully get a bunch of 'y' in the output. Hovewer, when I interrupt
console (2) to close the connection, the server crashes with following error


    await serve_websocket(echo_server, 'localhost', 8000, ssl_context=None)
  File "/usr/lib/python3.8/site-packages/trio_websocket-0.8.0-py3.8.egg/trio_websocket/_impl.py", line 374, in serve_websocket
    await server.run(task_status=task_status)
  File "/usr/lib/python3.8/site-packages/trio_websocket-0.8.0-py3.8.egg/trio_websocket/_impl.py", line 1345, in run
    await trio.sleep_forever()
  File "/usr/lib/python3.8/site-packages/trio/_core/_run.py", line 730, in __aexit__
    raise combined_error_from_nursery
  File "/usr/lib/python3.8/site-packages/trio/_highlevel_serve_listeners.py", line 129, in serve_listeners
    task_status.started(listeners)
  File "/usr/lib/python3.8/site-packages/trio/_core/_run.py", line 730, in __aexit__
    raise combined_error_from_nursery
  File "/usr/lib/python3.8/site-packages/trio/_highlevel_serve_listeners.py", line 27, in _run_handler
    await handler(stream)
  File "/usr/lib/python3.8/site-packages/trio_websocket-0.8.0-py3.8.egg/trio_websocket/_impl.py", line 1373, in _handle_connection
    await connection.aclose()
  File "/usr/lib/python3.8/site-packages/trio/_core/_run.py", line 730, in __aexit__
    raise combined_error_from_nursery
  File "/usr/lib/python3.8/site-packages/trio_websocket-0.8.0-py3.8.egg/trio_websocket/_impl.py", line 1148, in _reader_task
    await handler(event)
  File "/usr/lib/python3.8/site-packages/trio_websocket-0.8.0-py3.8.egg/trio_websocket/_impl.py", line 1071, in _handle_message_event
    await self._send_channel.send(msg)
  File "/usr/lib/python3.8/site-packages/trio/_channel.py", line 174, in send
    await trio.hazmat.wait_task_rescheduled(abort_fn)
  File "/usr/lib/python3.8/site-packages/trio/_core/_traps.py", line 165, in wait_task_rescheduled
    return (await _async_yield(WaitTaskRescheduled(abort_func))).unwrap()
  File "/usr/lib/python3.8/site-packages/outcome/_sync.py", line 111, in unwrap
    raise captured_error
trio.ClosedResourceError

I don't get any errors if I just use websocat and type messages by hand.

versions

~/s/l/p/tests [legimens]× » python --version       
Python 3.8.2

~/s/l/p/tests [legimens]× » pip show trio-websocket                       
Name: trio-websocket
Version: 0.8.0
[...]
~/s/l/p/tests [legimens]× » uname -a    
Linux archlinux 5.5.13-arch2-1 #1 SMP PREEMPT Mon, 30 Mar 2020 20:42:41 +0000 x86_64 GNU/Linux

Activity

  1. nmichaud commented on Sep 21, 2020

    @nmichaud
    Contributor

    I've been trying to debug this error as well - at first I thought it was my own code, but it seems to be easy to trigger when closing a connection from the client side while the server has a pending write.

  2. added a commit that references this issue on Sep 21, 2020
    2c015b1
  3. belm0 commented on Sep 22, 2020

    @belm0
    Member

    I'm blocked from making a bugfix release as I don't have admin access to the PyPI package. I'm trying to resolve it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions