[whatwg/streams] pipeTo: Read fullfilled after shutdown started (Issue #1207)

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:
> 
>   1. 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.)
>   2. 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.
https://searchfox.org/mozilla-central/rev/3de56eb5f266f523340e739ae1b53258e0a95dfe/js/src/builtin/streams/PipeToState.cpp#454-483

When working on my [new implementation](https://bugzilla.mozilla.org/show_bug.cgi?id=1734241) 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.


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

Message ID: <whatwg/streams/issues/1207@github.com>

Received on Saturday, 15 January 2022 16:57:33 UTC