{"action":"created","issue":{"url":"https://api.github.com/repos/websockets/ws/issues/964","repository_url":"https://api.github.com/repos/websockets/ws","labels_url":"https://api.github.com/repos/websockets/ws/issues/964/labels{/name}","comments_url":"https://api.github.com/repos/websockets/ws/issues/964/comments","events_url":"https://api.github.com/repos/websockets/ws/issues/964/events","html_url":"https://github.com/websockets/ws/issues/964","id":200123274,"number":964,"title":"'close' event firing too late","user":{"login":"cronvel","id":6891714,"avatar_url":"https://avatars2.githubusercontent.com/u/6891714?v=4","gravatar_id":"","url":"https://api.github.com/users/cronvel","html_url":"https://github.com/cronvel","followers_url":"https://api.github.com/users/cronvel/followers","following_url":"https://api.github.com/users/cronvel/following{/other_user}","gists_url":"https://api.github.com/users/cronvel/gists{/gist_id}","starred_url":"https://api.github.com/users/cronvel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cronvel/subscriptions","organizations_url":"https://api.github.com/users/cronvel/orgs","repos_url":"https://api.github.com/users/cronvel/repos","events_url":"https://api.github.com/users/cronvel/events{/privacy}","received_events_url":"https://api.github.com/users/cronvel/received_events","type":"User","site_admin":false},"labels":[{"id":170823324,"url":"https://api.github.com/repos/websockets/ws/labels/duplicate","name":"duplicate","color":"444444","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":9,"created_at":"2017-01-11T15:28:21Z","updated_at":"2017-07-22T05:53:10Z","closed_at":null,"body":"It seems that the 'close' event is emitted once the readyState is set to `CLOSED`.\r\n\r\nBut there is another readyState named `CLOSING` that does not emit anything, still, if `.send()` is called, it throws the ambiguous *Not opened* error. Since this `CLOSING` state doesn't last long (few milliseconds), this causes some rare bugs hard to reproduce. Usually, I receive the 'close' event up to 8ms after the error was thrown.\r\n\r\nChecking readyState before each `.send()` is an option, but it's not particularly nice, and since events are specifically designed to centralize clean up code, it would be great if:\r\n* either the 'close' event would be fired immediately once readyState is set to `CLOSING`\r\n* or if another event would be created specifically for that task, maybe 'end'\r\n\r\nIt's worth noting that listening the underlying socket does not help, the 'end' (in the Net Socket sense) event fire too late too. A potential 'end' event on the WebSocket object should be emitted as soon as the WebSocket is not writable anymore."},"comment":{"url":"https://api.github.com/repos/websockets/ws/issues/comments/317158191","html_url":"https://github.com/websockets/ws/issues/964#issuecomment-317158191","issue_url":"https://api.github.com/repos/websockets/ws/issues/964","id":317158191,"user":{"login":"lpinca","id":1443911,"avatar_url":"https://avatars0.githubusercontent.com/u/1443911?v=4","gravatar_id":"","url":"https://api.github.com/users/lpinca","html_url":"https://github.com/lpinca","followers_url":"https://api.github.com/users/lpinca/followers","following_url":"https://api.github.com/users/lpinca/following{/other_user}","gists_url":"https://api.github.com/users/lpinca/gists{/gist_id}","starred_url":"https://api.github.com/users/lpinca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lpinca/subscriptions","organizations_url":"https://api.github.com/users/lpinca/orgs","repos_url":"https://api.github.com/users/lpinca/repos","events_url":"https://api.github.com/users/lpinca/events{/privacy}","received_events_url":"https://api.github.com/users/lpinca/received_events","type":"User","site_admin":false},"created_at":"2017-07-22T05:53:10Z","updated_at":"2017-07-22T05:53:10Z","body":"Duplicate of #464."}}
{"actor":{"display_login":"lpinca"}}