python-trio / trio-websocket

WebSocket client and server implementation for Python Trio
MIT License
70 stars 26 forks source link

connection _close_message_queue() implementation #11

Closed belm0 closed 6 years ago

belm0 commented 6 years ago

I had a chance to review the code briefly, looks very good. One thing standing out as a little odd was the _close_message_queue() implementation:

https://github.com/HyperionGray/trio-websocket/blob/b787bf1a8a026ef1d9ca995d044bc97d42e7f727/trio_websocket/__init__.py#L204-L209

Possible issues:

mehaase commented 6 years ago

I'm not sure if that code is correct. It's definitely hacky and needs to be improved or replaced. Trio's upcoming channels feature sounds like it would work nicely, but it is unfinished.

Anyway, here's my reasoning behind that block. The goal is for any call to get_message() on a closed connection to raise ConnectionClosed, including calls made after the connection closed as well as calls made before the connection closed that are suspended in Queue.get().

Updated: I previously wrote that there was a bug in the ordering of the statements in lines 206-207, but on further reflection I think the ordering is fine.

mehaase commented 6 years ago

Fixed in #30.