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 49 commits into
base: jetty-12.1.x
Choose a base branch
from
Open

Cancel write semantic #12727

wants to merge 49 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.

@gregw
Copy link
Contributor Author

gregw commented Feb 12, 2025

@sbordet @lorban have you looked at this recently? Any updates for h2 or h3?

@lorban
Copy link
Contributor

lorban commented Feb 14, 2025

@gregw The H1 and H2 implementations have been reworked and are now tested.

What this PR lacks before it can be considered complete is handling a set of TODOs, javadoc, naming and minor potential improvements.

The H3 implementation has been deferred to after #12742 is merged, as that other PR changes too drastically the QUIC/H3 interactions so any work on the current impl would need to be completely re-done.

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

gregw commented Feb 18, 2025

@lorban can you re-review this PR and merge it?

@lorban
Copy link
Contributor

lorban commented Feb 19, 2025

@gregw Not yet, as I would like a firm confirmation that this PR solves the problem once and for all.

The #12776 issue is exactly about this bug, but not only: yesterday we discovered together with @sbordet that we have an extra bug (#12805) that still makes that user's use-case fail despite the fix in this PR.

I would like to get a confirmation from this user that 12.1 is working before merging this PR as he's been very willing to help, responsive and came up with a reliable reproducer.

@lorban lorban self-assigned this Feb 19, 2025
@lorban lorban added Bug For general bugs on Jetty side High Priority labels Feb 19, 2025
Signed-off-by: Ludovic Orban <[email protected]>
@lorban lorban force-pushed the fix/jetty-12.1.x/cancelWrite branch from 8d5dbd0 to 81927fe Compare February 21, 2025 08:09
Signed-off-by: Ludovic Orban <[email protected]>
Signed-off-by: Ludovic Orban <[email protected]>
@lorban
Copy link
Contributor

lorban commented Feb 21, 2025

The H3 implementation will come after #12742 gets merged.

@lorban
Copy link
Contributor

lorban commented Feb 21, 2025

@gregw @sbordet this PR is ready for its final review as I consider it ready to be merged

if (LOG.isDebugEnabled())
LOG.debug("cancelSend reset callback complete");
appCallback.failed(cause);
}));
Copy link
Contributor

Choose a reason for hiding this comment

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

_stream.reset() may still return early.

How about introducing a HTTP2Session.flush(Callback) that queues a "fake" FlushEntry into the HTTP2FLusher whose only scope is to be flushed and notify the callback when done?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll do that, and I'll also write a test similar to testResetAfterTCPCongestedWrite() that waits for idle timeout instead of resolving the TCP congestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For general bugs on Jetty side High Priority
Projects
Status: 👀 In review
Development

Successfully merging this pull request may close these issues.

ByteBufferPool - all ongoing requests fail when single request is cancelled on HTTP/2
3 participants