#268: HTML General Review: Web Sockets

Visit on Github.

Opened Apr 17, 2018

Hello TAG!

This issue is part of the TAG's larger effort to review the HTML spec in its entirety--please see the original issue https://github.com/w3ctag/design-reviews/issues/174 for a summary of all the break-out issues.

The "Sections" are all the sections of the WHATWG HTML spec that should be reviewed as part of this issue. Where the spec section has associated Web Platform Tests, the specific WPT path is noted. While the primary focus of the review is the specification text, it can be helpful to review the related tests to help clarify algorithms or see interoperability conformance issues (or find issues with the tests).

The "Features" are just a sample of what you will encounter as part of this spec section, it's not meant to be exhaustive.

Here are some example suggestions for what to look for during the review, but don't limit to only these suggestions!

  • Look for any APIs that could be 'modernized' according to current design practices.
  • Look for things that could require permissions that aren't modelled in the permissions API at the moment.
  • Look for areas of the platform that contain UA 'magic' (aren't possible for JavaScript programs to emulate due to missing primitives in the platform). These are candidates for future Extensible Web archeology.
  • Look for areas of the spec that describe "wishful thinking" (e.g., that describe a feature that is implemented by no one). Such features should at least have implementor commitments, or they might be candidates for removal from the spec.
  • Look for cryptic and hard-to-follow algorithms that could be improved with extra explanatory text or improved prose. E.g., sometimes adding a "developer note" (green box) can add the needed clarity to understand the intent/purpose or outcome of a complex concept.
  • Look for concepts that are meant to be used together, but where this is not spelled out or explained clearly
Sections WPT path Features
9.3 websockets WebSocket

Please provide feedback as (please select one):

  • open issues in our Github repo for each point of feedback
  • open a single issue in our Github repo for the entire review
  • leave review feedback as a comment in this issue and @-notify [github usernames]

Discussions

Comment by @ricea May 22, 2018 (See Github)

I don't know whether you want feedback from non-TAG members. I work on Chrome's WebSocket implementation. Some quick notes:

  • It would have been more convenient if we had a websocket.ready property returning a Promise instead of the onopen event.
  • The onerror event is useless -- it is the same as onclose with wasClean === false.
  • The default of 'blob' instead of 'arraybuffer' for binaryType leads to unpleasant surprises.
  • Lack of backpressure is unfortunate. If you can't keep up with the network you run out of CPU or RAM.
  • WHATWG Stream support would be nice.
Comment by @slightlyoff Jul 26, 2018 (See Github)

https://html.spec.whatwg.org/multipage/web-sockets.html

Comment by @slightlyoff Jul 26, 2018 (See Github)

hey @ricea,

We looked through Web Sockets today...and unsurprisingly we agree with you!

Do you happen to know if changing the binaryType default would be web compatible?

Agree that retrofitting with Promises and Streams would be very helpful. @ylafon, @cynthia, @kenchris, @travisleithead and I support a ready Promise (as it doesn't appear sockets can be reopened). Do you have opinions about how the socket closing should be modeled? Also as a Promise?

Also, in your view, would adding a Streaming interface be the right place to introduce backpressure?

Comment by @kenchris Jul 26, 2018 (See Github)

FYI, streams uses a getter for ready and not a method

Comment by @kenchris Jul 26, 2018 (See Github)

It should be possible to replace

void send(ArrayBuffer data);
void send(ArrayBufferView data);

with void send(BufferSource data); which is a typedef for both. https://heycam.github.io/webidl/#BufferSource

Comment by @slightlyoff Jul 26, 2018 (See Github)

@kenchris: Service Workers also use a getter: https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/ready

Comment by @ricea Jul 27, 2018 (See Github)

@slightlyoff Thanks for your response!

1.5% of messages received are Blobs (as opposed to 53% ArrayBuffers). Unfortunately I don't have data about how many blob-using connections set binaryType explicitly. We could collect more data but my gut feeling is that we can't change the default without breaking a lot of pages. There might be something clever we could do, but my mind is blank. At least we can tell that lots of people are finding the right button to push.

The reader and writer objects in the streams standard have a closed Promise which indicates when the stream is closed. I think this idea is almost directly applicable to the WebSocket API. Successful resolution means a clean close, rejection means some kind of error.

The streams interface is a really natural way to express backpressure. I've thought about having pause() and unpause() methods on the WebSocket object to let you control when the onmessage event is fired, but it's clunky by comparison.

Comment by @lgrahl Sep 17, 2018 (See Github)

Streams: We (some WebRTC spec folks) will start writing a streams extension for data channels soon. Since the API has been borrowed from Web Sockets, it should be easy to copy that work once we've done it.

https://github.com/w3c/webrtc-pc/issues/1732

Comment by @travisleithead Oct 30, 2018 (See Github)

Paris F2F: Looks like we've got some positive reactions here on the feedback. Since this was an unsolicited review request for HTML, I think the next step is to follow the WHATWG work mode for suggesting changes to Living Standards, and get an issue filed with the various feedback in it (or separate issues?), and then go about seeing if there is implementer interest, test changes, etc.

I'll see about filing this feedback soon-ish ;-)

Discussed Dec 4, 2018 (See Github)

Will wait for Travis to send issues in the WhatWG spec, bumped to next week

Discussed Jan 8, 2019 (See Github)

Travis: ... one remaining issue, but otherwise ready to close..

Comment by @travisleithead Jan 8, 2019 (See Github)

Issues filed (at long last), and looking forward to implementers expressing interest in the same. This concludes our TAG review of the WebSockets section of HTML. Thanks for flying TAG!