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

Fix flaky testUploadWithPendingReadConcurrentServerCloseClosesStream() #11693

Conversation

lorban
Copy link
Contributor

@lorban lorban commented Apr 24, 2024

Fixes #11692

…Stream()

Signed-off-by: Ludovic Orban <lorban@bitronix.be>
@lorban lorban requested a review from sbordet April 24, 2024 13:01
@lorban lorban self-assigned this Apr 24, 2024
joakime
joakime previously approved these changes Apr 24, 2024
</plugin>
</plugins>
</build>
</profile>
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this relevant for the fix?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not, but it avoids a warning from the JVM when running on JDK 22. Do you want me to move that change to another PR?

assertTrue(Content.Chunk.isFailure(lastChunk.get(), true));
assertInstanceOf(IOException.class, lastChunk.get().getFailure());
// Since the connector was stopped, there is no guarantee that
// the pending demand got serviced with an error chunk.
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not clear... you mean that the demand is not invoked at all, or that it is invoked, but not with an error chunk?

I think serverDemandLatch must be counted down, i.e. the demand must be invoked with an error chunk.
If the problem is that the connector is stopped when inside the demand callback with a normal chunk, then either we should convert the implementation into a loop (so we read the error chunk), or setting the demand when there was a failure should invoke immediately the demand again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem lies in HTTP2ServerConnection.onStreamFailure() which does the following:

Runnable task = channel.onFailure(failure, callback);
if (task != null)
{
    // We must dispatch to another thread because the task
    // may call application code that performs blocking I/O.
    offerTask(task, true); // true means call strategy.dispatch()
}

Since it is the task returned by channel.onFailure() that eventually services the demand, there is no guarantee that it's going to be executed as there is a race condition between the strategy's thread executing the queued task and the strategy being stopped because it is part of the connector being stopped.

…0.x/11692-fix-flaky-testUploadWithPendingReadConcurrentServerCloseClosesStream
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
@lorban
Copy link
Contributor Author

lorban commented Apr 26, 2024

@sbordet I've submitted an alternate fix for the flakyness of that test that requires a delicate change in HTTP2Connection to guarantee a pending demand is serviced even if the connector gets stopped.

@lorban lorban requested a review from sbordet April 26, 2024 12:36
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
@lorban lorban merged commit cfee4fe into jetty-12.0.x May 2, 2024
10 checks passed
@lorban lorban deleted the fix/jetty-12.0.x/11692-fix-flaky-testUploadWithPendingReadConcurrentServerCloseClosesStream branch May 2, 2024 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

HttpClientStreamTest.testUploadWithPendingReadConcurrentServerCloseClosesStream(Transport)[3] H2C is flaky
3 participants