Description
The spec is quite clear that after shutting down there should be no new reads. However there is an open question in Firefox's old implementation of pipeTo about what happens when a read is fulfilled after shutdown. I am quoting Waldos' comment in full below:
If |source| becomes errored not during a pending read, it's clear we must
react immediately.But what if |source| becomes errored during a pending read? Should this
first error, or the pending-read second error, predominate? Two semantics
are possible when |source|/|dest| become closed or errored while there's a
pending read:
- Wait until the read fulfills or rejects, then respond to the
closure/error without regard to the read having fulfilled or rejected.
(This will simply not react to the read being rejected, or it will
queue up the read chunk to be written during shutdown.)- React to the closure/error immediately per "Error and close states
must be propagated". Then when the read fulfills or rejects later, do
nothing.The spec doesn't clearly require either semantics. It requires that
already-read chunks be written (at least if |dest| didn't become errored
or closed such that no further writes can occur). But it's silent as to
not-fully-read chunks. (These semantic differences may only be observable
with very carefully constructed readable/writable streams.)It seems best, generally, to react to the temporally-earliest problem that
arises, so we implement option 2. (Blink, in contrast, currently
implements option 1.)All specified reactions to a closure/error invoke either the shutdown, or
shutdown with an action, algorithms. Those algorithms each abort if either
shutdown algorithm has already been invoked. So we don't need to do
anything special here to deal with a pending read.
When working on my new implementation I actually just ended up doing what is described as option 1 (aka Chrome's behavior). My own intuition here is that it would be better to not just drop an already read chunk onto the floor and at least try to write it. The write might of course still fail anyway, considering that we might cancel the stream during shutdown or release the writer.
Sorry if this has already been discussed somewhere else.