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

Fix ConnectionClosedError raised from websockets library #856

Closed
wants to merge 7 commits into from

Conversation

euri10
Copy link
Member

@euri10 euri10 commented Nov 19, 2020

Fixes #757

This looks right to me but I'm not a ws expert by any means, previous behaviour was calling the parent connection_lost even if the transport is not in a closing state, which I added, seems like it's ok

This said, given #760 , if some affected users could gently test this PR if it has any unwanted side-effects that would be cool, /poke https://github.com/stefanw and https://github.com/oTree-org

@euri10 euri10 marked this pull request as ready for review November 19, 2020 13:09
@oTree-org
Copy link

Hi @euri10 sorry! I just saw this (I didn't get the notification). I installed your branch but unfortunately I am getting the same traceback as before:

WARNING Error in opening handshake
Traceback (most recent call last):
  File "c:\otree\ve38\lib\site-packages\websockets\server.py", line 130, in handler
    path = await self.handshake(
  File "c:\otree\ve38\lib\site-packages\websockets\server.py", line 586, in handshake
    self.connection_open()
  File "c:\otree\ve38\lib\site-packages\websockets\protocol.py", line 328, in connection_open
    assert self.state is State.CONNECTING
AssertionError
WARNING Error in opening handshake
Traceback (most recent call last):
  File "c:\otree\ve38\lib\site-packages\websockets\server.py", line 130, in handler
    path = await self.handshake(
  File "c:\otree\ve38\lib\site-packages\websockets\server.py", line 586, in handshake
    self.connection_open()
  File "c:\otree\ve38\lib\site-packages\websockets\protocol.py", line 328, in connection_open
    assert self.state is State.CONNECTING
AssertionError
WARNING Error in opening handshake
Traceback (most recent call last):
  File "c:\otree\ve38\lib\site-packages\websockets\server.py", line 130, in handler
    path = await self.handshake(
  File "c:\otree\ve38\lib\site-packages\websockets\server.py", line 586, in handshake
    self.connection_open()
  File "c:\otree\ve38\lib\site-packages\websockets\protocol.py", line 328, in connection_open
    assert self.state is State.CONNECTING
AssertionError
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "c:\otree\ve38\lib\site-packages\uvicorn\protocols\websockets\websockets_impl.py", line 157, in run_asgi
    result = await self.app(self.scope, self.asgi_receive, self.asgi_send)
  File "c:\otree\ve38\lib\site-packages\uvicorn\middleware\proxy_headers.py", line 45, in __call__
    return await self.app(scope, receive, send)
  File "c:\otree\ve38\lib\site-packages\uvicorn\middleware\asgi2.py", line 7, in __call__
    await instance(receive, send)
  File "c:\otree\core\channels\sessions.py", line 183, in __call__
    return await self.inner(receive, self.send)
  File "c:\otree\core\channels\middleware.py", line 41, in coroutine_call
    await inner_instance(receive, send)
  File "c:\otree\core\channels\consumer.py", line 58, in __call__
    await await_many_dispatch(
  File "c:\otree\core\channels\utils.py", line 51, in await_many_dispatch
    await dispatch(result)
  File "c:\otree\core\channels\consumer.py", line 73, in dispatch
    await handler(message)
  File "c:\otree\core\channels\generic\websocket.py", line 175, in websocket_connect
    await self.connect()
  File "c:\otree\core\otree\channels\consumers.py", line 100, in connect
    await self.post_connect(**self.cleaned_kwargs)
  File "c:\otree\core\otree\channels\consumers.py", line 306, in post_connect
    await self.auto_advanced()
  File "c:\otree\core\otree\channels\consumers.py", line 309, in auto_advanced
    await self.send_json({'auto_advanced': True})
  File "c:\otree\core\channels\generic\websocket.py", line 273, in send_json
    await super().send(text_data=await self.encode_json(content), close=close)
  File "c:\otree\core\channels\generic\websocket.py", line 211, in send
    await super().send({"type": "websocket.send", "text": text_data})
  File "c:\otree\core\channels\consumer.py", line 81, in send
    await self.base_send(message)
  File "c:\otree\core\channels\sessions.py", line 236, in send
    return await self.real_send(message)
  File "c:\otree\ve38\lib\site-packages\uvicorn\protocols\websockets\websockets_impl.py", line 218, in asgi_send
    await self.send(data)
  File "c:\otree\ve38\lib\site-packages\websockets\protocol.py", line 555, in send
    await self.ensure_open()
  File "c:\otree\ve38\lib\site-packages\websockets\protocol.py", line 803, in ensure_open
    raise self.connection_closed_exc()
websockets.exceptions.ConnectionClosedError: code = 1006 (connection closed abnormally [internal]), no reason

Thank you and let me know if I can provide any more info!

@euri10
Copy link
Member Author

euri10 commented Nov 21, 2020

ok I'm going to close this if this doesnt fix it, I'm afraid I'm out of ideas as to what's happening

@euri10 euri10 closed this Nov 21, 2020
@oTree-org
Copy link

OK no problem, thank you for your help :)

@euri10 euri10 deleted the 757_ws_ConnectionClosedError branch December 27, 2020 19:24
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

Successfully merging this pull request may close these issues.

ConnectionClosedError raised from websockets library
2 participants