{"action":"created","issue":{"url":"https://api.github.com/repos/HyperionGray/trio-websocket/issues/22","repository_url":"https://api.github.com/repos/HyperionGray/trio-websocket","labels_url":"https://api.github.com/repos/HyperionGray/trio-websocket/issues/22/labels{/name}","comments_url":"https://api.github.com/repos/HyperionGray/trio-websocket/issues/22/comments","events_url":"https://api.github.com/repos/HyperionGray/trio-websocket/issues/22/events","html_url":"https://github.com/HyperionGray/trio-websocket/issues/22","id":358381870,"node_id":"MDU6SXNzdWUzNTgzODE4NzA=","number":22,"title":"client example not handling closed connection","user":{"login":"belm0","id":1708631,"node_id":"MDQ6VXNlcjE3MDg2MzE=","avatar_url":"https://avatars3.githubusercontent.com/u/1708631?v=4","gravatar_id":"","url":"https://api.github.com/users/belm0","html_url":"https://github.com/belm0","followers_url":"https://api.github.com/users/belm0/followers","following_url":"https://api.github.com/users/belm0/following{/other_user}","gists_url":"https://api.github.com/users/belm0/gists{/gist_id}","starred_url":"https://api.github.com/users/belm0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/belm0/subscriptions","organizations_url":"https://api.github.com/users/belm0/orgs","repos_url":"https://api.github.com/users/belm0/repos","events_url":"https://api.github.com/users/belm0/events{/privacy}","received_events_url":"https://api.github.com/users/belm0/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"mehaase","id":320904,"node_id":"MDQ6VXNlcjMyMDkwNA==","avatar_url":"https://avatars1.githubusercontent.com/u/320904?v=4","gravatar_id":"","url":"https://api.github.com/users/mehaase","html_url":"https://github.com/mehaase","followers_url":"https://api.github.com/users/mehaase/followers","following_url":"https://api.github.com/users/mehaase/following{/other_user}","gists_url":"https://api.github.com/users/mehaase/gists{/gist_id}","starred_url":"https://api.github.com/users/mehaase/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mehaase/subscriptions","organizations_url":"https://api.github.com/users/mehaase/orgs","repos_url":"https://api.github.com/users/mehaase/repos","events_url":"https://api.github.com/users/mehaase/events{/privacy}","received_events_url":"https://api.github.com/users/mehaase/received_events","type":"User","site_admin":false},"assignees":[{"login":"mehaase","id":320904,"node_id":"MDQ6VXNlcjMyMDkwNA==","avatar_url":"https://avatars1.githubusercontent.com/u/320904?v=4","gravatar_id":"","url":"https://api.github.com/users/mehaase","html_url":"https://github.com/mehaase","followers_url":"https://api.github.com/users/mehaase/followers","following_url":"https://api.github.com/users/mehaase/following{/other_user}","gists_url":"https://api.github.com/users/mehaase/gists{/gist_id}","starred_url":"https://api.github.com/users/mehaase/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mehaase/subscriptions","organizations_url":"https://api.github.com/users/mehaase/orgs","repos_url":"https://api.github.com/users/mehaase/repos","events_url":"https://api.github.com/users/mehaase/events{/privacy}","received_events_url":"https://api.github.com/users/mehaase/received_events","type":"User","site_admin":false}],"milestone":null,"comments":2,"created_at":"2018-09-09T14:15:47Z","updated_at":"2018-10-11T15:45:26Z","closed_at":null,"author_association":"COLLABORATOR","body":"The client example is not handling the case where server suddenly drops the connection, since it's blocked waiting for keyboard input.\r\n\r\nAlso there seems to be no reason that input is being run on a background thread, only to then await on the result.\r\n\r\nThere should be two tasks running in parallel: one to accept and process commands, and another to loop on `get_message()` and queue the results."},"comment":{"url":"https://api.github.com/repos/HyperionGray/trio-websocket/issues/comments/429006578","html_url":"https://github.com/HyperionGray/trio-websocket/issues/22#issuecomment-429006578","issue_url":"https://api.github.com/repos/HyperionGray/trio-websocket/issues/22","id":429006578,"node_id":"MDEyOklzc3VlQ29tbWVudDQyOTAwNjU3OA==","user":{"login":"mehaase","id":320904,"node_id":"MDQ6VXNlcjMyMDkwNA==","avatar_url":"https://avatars1.githubusercontent.com/u/320904?v=4","gravatar_id":"","url":"https://api.github.com/users/mehaase","html_url":"https://github.com/mehaase","followers_url":"https://api.github.com/users/mehaase/followers","following_url":"https://api.github.com/users/mehaase/following{/other_user}","gists_url":"https://api.github.com/users/mehaase/gists{/gist_id}","starred_url":"https://api.github.com/users/mehaase/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mehaase/subscriptions","organizations_url":"https://api.github.com/users/mehaase/orgs","repos_url":"https://api.github.com/users/mehaase/repos","events_url":"https://api.github.com/users/mehaase/events{/privacy}","received_events_url":"https://api.github.com/users/mehaase/received_events","type":"User","site_admin":false},"created_at":"2018-10-11T15:45:26Z","updated_at":"2018-10-11T15:45:26Z","author_association":"COLLABORATOR","body":"I've written up a quick implementation with an optional `cancel_scope` argument for client connections. This scope is cancelled when the connection closes. I updated the example client. Here's a sample run where the server closed the connection while the client was waiting for the user to enter a command.\r\n\r\n    (venv) $ python examples/client.py ws://localhost:8000/asdf\r\n    DEBUG:root:Connecting to WebSocket…\r\n    DEBUG:trio-websocket:Connecting to ws://localhost:8000/asdf?\r\n    DEBUG:trio-websocket:conn#0 sending 158 bytes\r\n    DEBUG:trio-websocket:conn#0 received 110 bytes\r\n    DEBUG:trio-websocket:conn#0 received event: ConnectionEstablished\r\n    DEBUG:root:Connected!\r\n    cmd> DEBUG:trio-websocket:conn#0 received zero bytes (connection closed)\r\n    DEBUG:trio-websocket:conn#0 websocket closed <ConnectionClosed <CloseReason code=1006 name=ABNORMAL_CLOSURE reason=None>>\r\n    DEBUG:trio-websocket:conn#0 reader task finished\r\n    DEBUG:root:Connection closed\r\n\r\nI don't love this implementation. It doesn't provide an easy way for the user to know that the server closed the connection. It also adds another argument to the `WebSocketConnection` constructor and the client factory functions. Definitely welcoming any feedback here...\r\n\r\nOther possible implementations:\r\n\r\n* **Add a [synchronous] callback function that is called when the connection closes.** This still pollutes the arguments for the constructor/factories, but it is more general than cancellation and the close reason could be passed to the callback.\r\n* **Add an `async def wait_closed()` function that blocks until the connection closes and then returns the close reason.** This _does not pollute_ the arguments for the constructor/factories, is more general than cancellation, and provides the close reason to the caller. I think this is my favorite approach but I worry that it is over-engineered, especially since I don't have any use cases for this \"handle connection closed immediately\" behavior other than the example client.\r\n\r\nThoughts?\r\n"}}
{"actor":{"display_login":"mehaase"}}