Skip to content
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

Merged
merged 4 commits into from
Aug 27, 2015
Merged

Add IsReadableStreamDisturbed predicate #385

merged 4 commits into from
Aug 27, 2015

Conversation

tyoshino
Copy link
Member

@tyoshino tyoshino commented Aug 3, 2015

See the suggestion in the OP of #378.

@tyoshino
Copy link
Member Author

tyoshino commented Aug 3, 2015

The disturbed flag is never changed when the streams is closed. Is it assumed that this is implemented after removing the auto-release feature?

@yutakahirano
Copy link
Member

@@ -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
Copy link
Member

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"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@domenic
Copy link
Member

domenic commented Aug 3, 2015

The disturbed flag is never changed when the streams is closed. Is it assumed that this is implemented after removing the auto-release feature?

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.

@tyoshino
Copy link
Member Author

tyoshino commented Aug 4, 2015

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?

@domenic
Copy link
Member

domenic commented Aug 4, 2015

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 new Request(otherRequest). This is important because it means that author code that acts similar to json() will also make the stream disturbed.

@tyoshino
Copy link
Member Author

tyoshino commented Aug 5, 2015

Addressed the comment. Thanks.

This is important because it means that author code that acts similar to json() will also make the stream disturbed.

OK. But an operation made on a released reader making the ex-associated stream disturbed sounds strange.

@domenic
Copy link
Member

domenic commented Aug 5, 2015

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?

@domenic
Copy link
Member

domenic commented Aug 17, 2015

Ping. What are your thoughts?

@yutakahirano
Copy link
Member

I prefer dropping auto-release to introducing released-but-still-connected state.

@domenic
Copy link
Member

domenic commented Aug 18, 2015

That seems like a good compromise to me. @tyoshino do you want to do the PR or shall I?

@domenic
Copy link
Member

domenic commented Aug 18, 2015

Actually, I can do that; there is other work I want to do on top of it. I will send a PR later today.

domenic added a commit that referenced this pull request Aug 18, 2015
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.
@domenic
Copy link
Member

domenic commented Aug 18, 2015

OK, I have pushed to this PR with a base commit that removes automatic unlocking on close/error.

Two important questions:

  • Should we now reject read() and closed when used on released readers, instead of treating as a closed/errored stream? That seems simpler. I have not implemented it yet.
  • Are we OK with breaking compat on this? It would be a breaking change to Chrome's current behavior, and a change in an area of the spec we've called stable. I personally think it is unlikely to break things, but what do you think? /cc @yutakahirano @calvaris

@calvaris
Copy link
Contributor

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.

@domenic
Copy link
Member

domenic commented Aug 19, 2015

@calvaris thanks for weighing in! I made a bunch of test updates in 9945ae1 but if you can think of others we should add them. E.g. if you come up with test descriptions I'll write the tests :)

@yutakahirano
Copy link
Member

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.

@domenic
Copy link
Member

domenic commented Aug 19, 2015

@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?

@yutakahirano
Copy link
Member

But I take it you think that is bad?

Yes.

@domenic
Copy link
Member

domenic commented Aug 19, 2015

OK. Does anyone have any opinion on

Should we now reject read() and closed when used on released readers, instead of treating as a closed/errored stream?

@domenic
Copy link
Member

domenic commented Aug 20, 2015

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.

@domenic domenic added this to the Week of 2015-08-24 milestone Aug 20, 2015
@tyoshino
Copy link
Member Author

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.

@domenic
Copy link
Member

domenic commented Aug 25, 2015

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.
Copy link
Member Author

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"?

Copy link
Member Author

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?

Copy link
Member Author

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.

@tyoshino
Copy link
Member Author

Review done!

domenic and others added 4 commits August 27, 2015 15:49
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.
@domenic
Copy link
Member

domenic commented Aug 27, 2015

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.

@domenic domenic merged commit 632b26a into master Aug 27, 2015
@yutakahirano
Copy link
Member

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.

@yutakahirano
Copy link
Member

@wanderview: ping

@wanderview
Copy link
Member

I'm sorry, but I haven't been able to keep up with this. Can you summarize
the differences from the July f2f agreement?

Are we just dropping automatic unlocking on stream close?
On Sep 10, 2015 10:18 PM, "Yutaka Hirano" notifications@github.com wrote:

@wanderview https://github.com/wanderview: ping


Reply to this email directly or view it on GitHub
#385 (comment).

@yutakahirano
Copy link
Member

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:

  1. Auto-released reader makes the stream disturbed.
  2. Remove the auto-release mechanism.

My opinion is that the latter is less evil.

Are we just dropping automatic unlocking on stream close?

And on stream error.

@wanderview
Copy link
Member

Remove the auto-release mechanism.

I think this is reasonable. Thanks for summarizing for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants