-
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
base: jetty-12.1.x
Are you sure you want to change the base?
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.
Signed-off-by: Ludovic Orban <[email protected]>
public Callback cancel(Throwable cause, Callback callback) | ||
{ | ||
Callback nested = new Callback.Nested(callback) | ||
{ | ||
@Override | ||
public void succeeded() | ||
{ | ||
super.failed(cause); | ||
} | ||
|
||
@Override | ||
public void failed(Throwable x) | ||
{ | ||
ExceptionUtil.addSuppressedIfNotAssociated(cause, x); | ||
super.failed(cause); | ||
} | ||
}; | ||
reset(HTTP3ErrorCode.REQUEST_CANCELLED_ERROR.code(), cause); | ||
return nested; | ||
} |
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.
@lorban that looks simple enough. Same as h2. Any idea how to test this?
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.
This is the big question: the implementation looks fairly easy but I've been scratching my head trying to find a way to reliably test that.
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.
Same comment as HTTP/2.
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
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
@@ -13,6 +13,7 @@ | |||
|
|||
package org.eclipse.jetty.http2.frames; | |||
|
|||
@Deprecated (forRemoval = true, since = "12.1.0") |
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.
Why deprecating this?
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.
because it is not used
...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
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
@@ -267,7 +309,7 @@ public void write(Callback callback, SocketAddress address, ByteBuffer... buffer | |||
if (DEBUG) | |||
LOG.debug("write: {} {}", this, BufferUtil.toDetailString(buffers)); | |||
|
|||
if (!updateState(__IDLE, __WRITING)) | |||
if (!updateState(__IDLE, __FLUSHING)) |
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 probably need a new isCancelled() { callback.fail(); return; }
check before this updateState()
.
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.
why? if it is cancelled then it will not be in idle state?
@@ -267,7 +309,7 @@ public void write(Callback callback, SocketAddress address, ByteBuffer... buffer | |||
if (DEBUG) | |||
LOG.debug("write: {} {}", this, BufferUtil.toDetailString(buffers)); | |||
|
|||
if (!updateState(__IDLE, __WRITING)) | |||
if (!updateState(__IDLE, __FLUSHING)) | |||
throw new WritePendingException(); |
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.
Now that I see this, it looks wrong: throwing from a method that takes a callback feels like an anti-pattern.
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 agree, but this pre-dates this PR. Should we fix this in another PR?
jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/WriteFlusher.java
Show resolved
Hide resolved
else | ||
ExceptionUtil.callAndThen(x, t -> _buffer.releaseAndRemove(), callback::failed); | ||
ExceptionUtil.callAndThen(x, t -> _buffer.release(), callback::failed); |
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'm surprised this is the only place where we called releaseAndRemove()
, I'm surprised HttpOutput
for instance did not.
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.
Oh, it does in 12.0 but not in 12.1!
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.
Oh no! We have missed some merges from 12.0! That needs to be investigated!
Added a cancel write/send semantic so that buffers for failed writes need not be removed from the pool