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

RetainableByteBuffer.DynamicCapacity enters a corrupt state when released #12082

Closed
lorban opened this issue Jul 24, 2024 · 0 comments · Fixed by #12083
Closed

RetainableByteBuffer.DynamicCapacity enters a corrupt state when released #12082

lorban opened this issue Jul 24, 2024 · 0 comments · Fixed by #12083
Assignees
Labels
Bug For general bugs on Jetty side

Comments

@lorban
Copy link
Contributor

lorban commented Jul 24, 2024

Jetty version(s)
12.1.x

Description
HttpClientTransportOverHTTP2Test.testClientStopsServerDoesNotCloseClientCloses() illustrates the problem.

When you run that test, it passes but dumps the following stack trace to stderr:

java.lang.IllegalStateException: already released ReferenceCounter@7bd4937b[r=0]
	at org.eclipse.jetty.io.Retainable$ReferenceCounter.lambda$release$2(Retainable.java:226)
	at java.base/java.util.concurrent.atomic.AtomicInteger.updateAndGet(AtomicInteger.java:281)
	at org.eclipse.jetty.io.Retainable$ReferenceCounter.release(Retainable.java:223)
	at org.eclipse.jetty.io.Retainable$Wrapper.release(Retainable.java:149)
	at org.eclipse.jetty.io.RetainableByteBuffer$DynamicCapacity.release(RetainableByteBuffer.java:1913)
	at org.eclipse.jetty.http2.tests.HttpClientTransportOverHTTP2Test$13.writeFrames(HttpClientTransportOverHTTP2Test.java:602)
	at org.eclipse.jetty.http2.tests.HttpClientTransportOverHTTP2Test$13.onHeaders(HttpClientTransportOverHTTP2Test.java:588)
	at org.eclipse.jetty.http2.parser.BodyParser.notifyHeaders(BodyParser.java:115)
	at org.eclipse.jetty.http2.parser.HeadersBodyParser.onHeaders(HeadersBodyParser.java:269)
	at org.eclipse.jetty.http2.parser.HeadersBodyParser.onHeaders(HeadersBodyParser.java:264)
	at org.eclipse.jetty.http2.parser.HeadersBodyParser.parse(HeadersBodyParser.java:208)
	at org.eclipse.jetty.http2.parser.Parser.parseBody(Parser.java:229)
	at org.eclipse.jetty.http2.parser.Parser.parse(Parser.java:156)
	at org.eclipse.jetty.http2.parser.ServerParser.parse(ServerParser.java:121)
	at org.eclipse.jetty.http2.tests.HttpClientTransportOverHTTP2Test.testClientStopsServerDoesNotCloseClientCloses(HttpClientTransportOverHTTP2Test.java:618)
	...

This happens because writeFrames() is called more than once, and itself calls RetainableByteBuffer.DynamicCapacity.release().

The first time writeFrames() is called, everything works as expected: release() figures out it's time to cleanup and does it well.
The second time, release() relies on a ReferenceCounter instance held it a superclass that was not reset by the first call, hence it throws the above exception to complain that release was already performed. Unfortunately, in the meantime the dynamic capacity accumulator was asked to accumulate, and it did without error. At this point in time, RetainableByteBuffer.DynamicCapacity contains lifecycled resources that it does not correctly track and is incapable of releasing.

@lorban lorban added the Bug For general bugs on Jetty side label Jul 24, 2024
@lorban lorban self-assigned this Jul 24, 2024
@lorban lorban moved this to 🏗 In progress in Jetty 12.1.0 Jul 24, 2024
lorban added a commit that referenced this issue Jul 24, 2024
lorban added a commit that referenced this issue Aug 6, 2024
Signed-off-by: Ludovic Orban <[email protected]>
lorban added a commit that referenced this issue Aug 7, 2024
lorban added a commit that referenced this issue Aug 7, 2024
lorban added a commit that referenced this issue Aug 29, 2024
#12082 Add assertions to DynamicCapacity to avoid entering an undetected corrupt state after it is released.

Signed-off-by: Ludovic Orban <[email protected]>
@lorban lorban closed this as completed Oct 2, 2024
@github-project-automation github-project-automation bot moved this from 🏗 In progress to ✅ Done in Jetty 12.1.0 Oct 2, 2024
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
Projects
Status: ✅ Done
Development

Successfully merging a pull request may close this issue.

1 participant