Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
danlkv opened this issue Apr 26, 2020 · 2 comments
Closed

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

danlkv opened this issue Apr 26, 2020 · 2 comments

Comments

@danlkv
Copy link

danlkv commented Apr 26, 2020

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

@nmichaud
Copy link
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.

nmichaud added a commit to nmichaud/trio-websocket that referenced this issue Sep 21, 2020
@belm0 belm0 closed this as completed in 50b62cb Sep 22, 2020
@belm0
Copy link
Member

belm0 commented Sep 22, 2020

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants