-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Cancel write semantic #12727
Cancel write semantic #12727
Conversation
Provide a write cancel mechanism so that removing pooled buffers can be avoided.
Provide a write cancel mechanism so that removing pooled buffers can be avoided.
…1.x/cancelWrite
Signed-off-by: Ludovic Orban <[email protected]>
...y-core/jetty-http3/jetty-http3-common/src/main/java/org/eclipse/jetty/http3/HTTP3Stream.java
Outdated
Show resolved
Hide resolved
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 am dubious about the H2/h3 implementation; we should talk about it.
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/HttpStream.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/HttpStream.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/internal/HttpConnection.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/internal/HttpConnection.java
Show resolved
Hide resolved
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/internal/HttpConnection.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/WriteFlusher.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/WriteFlusher.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/internal/HttpConnection.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/WriteFlusher.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/WriteFlusher.java
Show resolved
Hide resolved
...-core/jetty-http2/jetty-http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Session.java
Outdated
Show resolved
Hide resolved
...y-http2/jetty-http2-common/src/main/java/org/eclipse/jetty/http2/frames/DisconnectFrame.java
Show resolved
Hide resolved
...ty-http2/jetty-http2-common/src/main/java/org/eclipse/jetty/http2/internal/HTTP2Flusher.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/EndPoint.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/HttpStream.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/WriteFlusher.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/internal/HttpConnection.java
Show resolved
Hide resolved
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/internal/HttpConnection.java
Outdated
Show resolved
Hide resolved
@gregw another issue is the use of So it has not the right semantic for the usage that was done in H2 and H3. |
@sbordet See new |
Signed-off-by: Ludovic Orban <[email protected]>
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 believe the mechanism is sane, but I can't wrap my head around the newly introduced API and how this should all work.
I've attempted to write a test for this functionality (I've pushed it to this PR) and that left me puzzled. We should probably discuss it.
jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/WriteFlusher.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/WriteFlusher.java
Show resolved
Hide resolved
jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/WriteFlusher.java
Show resolved
Hide resolved
jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/WriteFlusher.java
Show resolved
Hide resolved
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ErrorHandler.java
Show resolved
Hide resolved
Signed-off-by: Ludovic Orban <[email protected]>
Signed-off-by: Ludovic Orban <[email protected]>
...y-core/jetty-http2/jetty-http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Stream.java
Outdated
Show resolved
Hide resolved
...etty-http2/jetty-http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2StreamEndPoint.java
Outdated
Show resolved
Hide resolved
.../jetty-http2/jetty-http2-common/src/main/java/org/eclipse/jetty/http2/frames/FlushFrame.java
Outdated
Show resolved
Hide resolved
...-http2-server/src/main/java/org/eclipse/jetty/http2/server/internal/HttpStreamOverHTTP2.java
Outdated
Show resolved
Hide resolved
...-http2-server/src/main/java/org/eclipse/jetty/http2/server/internal/HttpStreamOverHTTP2.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Simone Bordet <[email protected]>
...etty-http2/jetty-http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2StreamEndPoint.java
Outdated
Show resolved
Hide resolved
Added a new Callback.Combination rather than the Callback.collection method
Improved Callback.Combination as an Autocloseable
Improved Callback.Combination as an Autocloseable
...etty-http2/jetty-http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2StreamEndPoint.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/Callback.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/Callback.java
Outdated
Show resolved
Hide resolved
int s = state.getStamp(); | ||
Throwable failure = state.getReference(); |
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 think you want to take them atomically, so here you should use state.get(int[])
.
Likewise in the other places.
Actually, my suggestion of AtomicStampedReference
was more to handle the Callback
and the counter together... Now that the callback is final
, I don't think we need AtomicStampedReference
anymore, we can split again failure and counter, as now we just use the counter as the state of all the callbacks.
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.
We don't need to take them atomically. If they change between one get and the next, then the CaS will fail anyway. I guess it is only a single volatile lookup, so maybe better... I'll have a look at it
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 would prefer just AtomicInteger
for the counter at this point.
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 think the stamped reference is better. There are still some races with multiple failures that this solves and gives us more deterministic behaviour.
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/Callback.java
Outdated
Show resolved
Hide resolved
Improved Callback.Combination as an Autocloseable
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/Callback.java
Outdated
Show resolved
Hide resolved
|
||
// If the stamp is < 0, the combination has not been closed, so we increment, else we decrement. | ||
int n = s < 0 ? s + 1 : s - 1; | ||
if (!state.compareAndSet(failure, combined, s, n)) |
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.
If this CAS fails, is exception combination above safe?
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.
It is. Failure will only go from null to non-null once and then stay at that value. So we are not trying to hit a moving target. If the cas fails, then the addSuppressed will not add the same exception again, because they will already be associated. But it will be the same target failure, so the previous addSuppressed was the correct thing to do.
Note, it is because of this slight complex race that I had the failure logic after the CaS, but before the the andThen
callback. I think it is safe there as well with less thought needed, but you asked me to move it. I think it is probably better where it is now.
@sbordet I'm going to try to get a clean CI build before merging. I think the failures are flakes or CI issues... but will check. Also, what is the plan for 12.0.x? Can any of this be backported easily? The h2 reset fix? |
Plan for 12.0.x is to rely on |
🎉 |
Added a cancel write/send semantic so that buffers for failed writes need not be removed from the pool