-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add IsReadableStreamDisturbed predicate #385
Conversation
The disturbed flag is never changed when the streams is closed. Is it assumed that this is implemented after removing the auto-release feature? |
@@ -300,6 +300,11 @@ Instances of <code>ReadableStream</code> are created with the internal slots des | |||
state and queue of this stream | |||
</tr> | |||
<tr> | |||
<td>\[[disturbed]] | |||
<td>A boolean flag set to <b>true</b> when either <code>read()</code> or <code>cancel()</code> has been called on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better phrased as "when the stream has been read from or canceled"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
I don't think we need to remove auto-release. However, as @yutakahirano notes, I think it was important (for reasons I forget) to have the disturbed flag change even on closed streams. As such it should probably move up a few steps in the algorithms. |
Maybe one of the origins of the requirement is yutakahirano/fetch-with-streams#37 (comment) ? Is it still active? whatwg/fetch#61 (comment) Or even if it's active, it'll be covered by used flag? |
Reviewing https://etherpad.mozilla.org/streams-f2f-july "Even more conservative strawman" I think the requirement comes from wanting .json() etc. to automatically make the stream disturbed, even for empty streams. The used flag is only for |
Addressed the comment. Thanks.
OK. But an operation made on a released reader making the ex-associated stream disturbed sounds strange. |
Oh, you are right. It would mean that getting a reader for a closed/error stream would still have to hold on to the stream in order to maybe mark it disturbed. This seems a bit silly. It means you cannot GC the stream if the reader is still alive, even though the stream is closed or errored. But that is maybe not so bad since closed or errored streams do not have any data in their internal queue. Also it would eliminate some internal complexity from the reader (the [[state]] and [[storedError]] fields). And the silliness seems less bad than debating bodyUsed all over again. What do you think? |
Ping. What are your thoughts? |
I prefer dropping auto-release to introducing released-but-still-connected state. |
That seems like a good compromise to me. @tyoshino do you want to do the PR or shall I? |
Actually, I can do that; there is other work I want to do on top of it. I will send a PR later today. |
Per #385, the current auto-unlocking design interferes with the implementation of the disturbed flag for fetch. It was never that useful anyway, so removing it is probably the best solution.
OK, I have pushed to this PR with a base commit that removes automatic unlocking on close/error. Two important questions:
|
I think it is also unlikely that we break things. Our current implementation is also based on closed/errored so it would mean to change our current implementation, which I'm not a big fan of but it wouldn't be a big change either, so I'm against but only barely and based on laziness :) What I would do is securing the change of behavior if it happens with some tests ensuring that everything is as it should be and not as it was. |
I believe we cannot introduce IsDisturbed with satisfying all proposed requirements and all existing properties. I think dropping the auto-release is a tolerable way. |
@yutakahirano well, we can introduce it without any backward-incompatible changes if we follow #385 (comment) and allow readers to retain references to their owner stream even after release. But I take it you think that is bad? |
Yes. |
OK. Does anyone have any opinion on
|
My opinion is that they should now reject. That will allow us to get rid of the internal slots [[state]] and [[storedError]]. The downside is that you would no longer get to treat released readers as closed/errored streams depending on their originating stream. Instead they would effectively behave as if they always came from errored streams. But I don't think that's a big deal; you shouldn't be messing with the reader after it's been released. |
Sorry for delay. I'm fine with the plan. I don't come up with any reasonable use case to keep a reference to a reader while releasing the parent stream. Some code may be accidentally doing so, but could be easily fixed and as Domenic said it's not so harmful to hold an errored/closed stream (which is small) in addition to a reader. I'm also fine with making read on released reader reject. I think currently people who are unaware of the auto release mechanism are not calling release(), and basically people who are aware of wouldn't read() on released one. Some may be using release() and also using released reader as a representation of closed stream that accepts read() and tell us that the stream is closed repeatedly. But ... maybe the number of users with such a use case is small, I guess. |
OK. Updated with what I think should be final. Cannot build the spec until speced/bikeshed#466 is fixed, but ready for review. |
@@ -855,7 +848,10 @@ Instances of <code>ReadableStreamReader</code> are created with the internal slo | |||
1. If IsReadableStreamReader(*this*) is *false*, throw a *TypeError* exception. | |||
1. If *this*@[[ownerReadableStream]] is *undefined*, return *undefined*. | |||
1. If *this*@[[readRequests]] is not empty, throw a *TypeError* exception. | |||
1. Perform CloseReadableStreamReader(*this*). | |||
1. If *this*@[[ownerReadableStream]]@[[state]] is `"readable"`, reject *this*@[[closedPromise]] with a *TypeError* exception. | |||
1. Otherwise, let *this*@[[closedPromise]] be a new promise rejected with a *TypeError* exception. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought "let" is used for declaring/substituting to local variables while set is used for substituting new value to a slot. I'm just misunderstanding your style rule or this "let" should be "set"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need to set a new rejected promise to [[closedPromise]] here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see. This new rejected promise and the TypeError at L851 are representing "already released". Then, looks good.
Review done! |
Per #385, the current auto-unlocking design interferes with the implementation of the disturbed flag for fetch. It was never that useful anyway, so removing it is probably the best solution.
This significantly simplifies the internals of readers, and their interaction with their owner stream.
Thanks for the review! I turns out I failed to do spec changes for the "Remove automatic unlocking on close/error" commit. Your let vs. set catch was correct as well. Fixed and will merge now. |
Just a confirmation: @wanderview, are you OK with this change? I am planning to implement this behavior change to Chrome, and before that I would like to make sure that everyone is satisfied. |
@wanderview: ping |
I'm sorry, but I haven't been able to keep up with this. Can you summarize Are we just dropping automatic unlocking on stream close?
|
The f2f agreement suggests a stream should be disturbed when read even if it is closed (See yutakahirano/fetch-with-streams#48 (comment)). In order to achieve that, there are two ways:
My opinion is that the latter is less evil.
And on stream error. |
I think this is reasonable. Thanks for summarizing for me. |
See the suggestion in the OP of #378.