[whatwg/streams] Do not allow abort to happen when a close is about to happen (#634)

As of #619, writer.abort() does not disturb the stream while an underlying-sink write or close operation is ongoing. However, it was still possible to cause both underlying sink abort and close to happen, with code like `writer.close(); writer.abort()`. This was because of the asynchronous way in which the stream's state transitions from "closing" to actually having [[inClose]] set to true.

This addresses that problem by peeking at the queue when abort is called. If the state is [[closing]], and the queue contains no writes, we will not perform the underlying abort, and instead just let the underlying close happen. This counts as a success, so we immediately return a promise fulfilled with undefined.

Fixes #632.

---

Careful review appreciated. A couple points worth questioning:

- This mechanism of peeking at the queue seems a bit suspect. I wonder if [[inClose]] is redundant with this, and we could consolidate somehow?
- I'm not sure immediately returning a promise fulfilled with undefined is correct. What if closing fails? It would be better to return the appropriate underlying sink close promise, but that doesn't exist yet... hmm. Maybe we should just call WritableStreamDefaultControllerClose?
- This behaves differently if the abort() happened during a write, as shown by the test. That is: write(); close(); abort(); will call the underlying abort, whereas just close(); abort(); will cause it to become closed. I think this seems correct, but I'm not sure.
You can view, comment on, or merge this pull request online at:

  https://github.com/whatwg/streams/pull/634

-- Commit Summary --

  * Do not allow abort to happen when a close is about to happen

-- File Changes --

    M index.bs (13)
    M reference-implementation/lib/writable-stream.js (7)
    M reference-implementation/to-upstream-wpts/writable-streams/aborting.js (94)

-- Patch Links --

https://github.com/whatwg/streams/pull/634.patch
https://github.com/whatwg/streams/pull/634.diff

-- 
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/634

Received on Monday, 19 December 2016 21:52:07 UTC