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

Cancel write semantic #12727

Open
wants to merge 13 commits into
base: jetty-12.1.x
Choose a base branch
from
Open

Cancel write semantic #12727

wants to merge 13 commits into from

Conversation

gregw
Copy link
Contributor

@gregw gregw commented Jan 22, 2025

Added a cancel write/send semantic so that buffers for failed writes need not be removed from the pool

gregw added 2 commits January 22, 2025 17:41
Provide a write cancel mechanism so that removing pooled buffers can be avoided.
@gregw gregw requested review from sbordet and lorban January 22, 2025 08:09
@gregw
Copy link
Contributor Author

gregw commented Jan 22, 2025

@sbordet can you implement the cancel semantic for http2. @lorban ditto for http3

gregw and others added 6 commits January 22, 2025 12:48
Comment on lines 64 to 83
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;
}
Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor

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.

@gregw
Copy link
Contributor Author

gregw commented Jan 29, 2025

@sbordet @lorban nudge for actual review

Copy link
Contributor

@sbordet sbordet left a 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.

@@ -13,6 +13,7 @@

package org.eclipse.jetty.http2.frames;

@Deprecated (forRemoval = true, since = "12.1.0")
Copy link
Contributor

Choose a reason for hiding this comment

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

Why deprecating this?

Copy link
Contributor Author

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

@gregw gregw requested review from lorban and sbordet January 31, 2025 15:53
@sbordet
Copy link
Contributor

sbordet commented Jan 31, 2025

@gregw another issue is the use of CountingCallback: it has the semantic to count for successes, but it fails on the first failure.

So it has not the right semantic for the usage that was done in H2 and H3.

@gregw
Copy link
Contributor Author

gregw commented Feb 4, 2025

@gregw another issue is the use of CountingCallback: it has the semantic to count for successes, but it fails on the first failure.

So it has not the right semantic for the usage that was done in H2 and H3.

@sbordet See new static List<Callback> from(Callback callback, Throwable cause, int count) method that replaces CountingCallback

Signed-off-by: Ludovic Orban <[email protected]>
Copy link
Contributor

@lorban lorban left a 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.

@@ -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))
Copy link
Contributor

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().

Copy link
Contributor Author

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();
Copy link
Contributor

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.

Copy link
Contributor Author

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?

else
ExceptionUtil.callAndThen(x, t -> _buffer.releaseAndRemove(), callback::failed);
ExceptionUtil.callAndThen(x, t -> _buffer.release(), callback::failed);
Copy link
Contributor

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.

Copy link
Contributor

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!

Copy link
Contributor Author

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!

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

Successfully merging this pull request may close these issues.

3 participants