Re: [whatwg/streams] Update WebSocket examples (#713)

ricea commented on this pull request.



>      });
+
+    function closeWS(code, reasonString) {
+      return new Promise((resolve, reject) => {
+        ws.onclose = e => {

Chrome definitely sets wasClean to false. 

For me the most important sentence is this from RFC6455 section 7.1.7:

   An endpoint MUST NOT continue to attempt to
   process data (including a responding Close frame) from the remote
   endpoint after being instructed to _Fail the WebSocket Connection_.

If we're prohibited from processing the Close frame from the server, there's no way to complete the closing handshake, and so it can't ever be clean.

This is actually quite subtle and it's possible other implementations have read the spec differently. There are a bunch of web-platform-tests where the test expects wasClean = true but Chrome sets it to false, but in my brief investigation it appears this is an interoperability issue with the test server, rather than being caused by any subtle issues.

I think from a standard's point of view, using wasClean in this way should totally work. For compatibility, you might want to have an additional wasOnErrorCalled flag. Personally I think the example should aim for brevity rather than maximum compatibility.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/pull/713#discussion_r108401828

Received on Tuesday, 28 March 2017 12:04:40 UTC