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

ContentSourceTransformer.read() may call release() more than once #12855

Open
lorban opened this issue Mar 4, 2025 · 3 comments · May be fixed by #12865
Open

ContentSourceTransformer.read() may call release() more than once #12855

lorban opened this issue Mar 4, 2025 · 3 comments · May be fixed by #12865
Assignees
Labels
Bug For general bugs on Jetty side

Comments

@lorban
Copy link
Contributor

lorban commented Mar 4, 2025

Jetty version(s)
12.1.x

Description
After ContentSourceTransformer.fail(x, true) is called, each call to ContentSourceTransformer.read() calls ContentSourceTransformer.release().

If the implementation does not implement release() in an idempotent way, ContentSourceTransformer.read() may throw or misbehave.

How to reproduce?

Here is a test to be added to GzipDecoderSourceTest that illustrates the bug for GzipDecoderSource:

@ParameterizedTest
@MethodSource("textResources")
public void testTransformerBug(String textResourceName) throws Exception
{
    startGzip();
    String compressedName = String.format("%s.%s", textResourceName, gzip.getFileExtensionNames().get(0));
    Path compressed = MavenPaths.findTestResourceFile(compressedName);

    Content.Source fileSource = Content.Source.from(sizedPool, compressed);
    Content.Source decoderSource = gzip.newDecoderSource(fileSource);

    decoderSource.fail(new Throwable(), true);

    Content.Chunk chunk1 = decoderSource.read();
    Content.Chunk chunk2 = decoderSource.read();
    Content.Chunk chunk3 = decoderSource.read(); // this throws NPE
}

which fails with:

java.lang.NullPointerException: Inflater has been closed

	at java.base/java.util.zip.Inflater.ensureOpen(Inflater.java:714)
	at java.base/java.util.zip.Inflater.reset(Inflater.java:685)
	at [email protected]/org.eclipse.jetty.util.compression.InflaterPool.reset(InflaterPool.java:56)
	at [email protected]/org.eclipse.jetty.util.compression.InflaterPool.reset(InflaterPool.java:21)
	at [email protected]/org.eclipse.jetty.util.compression.CompressionPool$Entry.release(CompressionPool.java:142)
	at [email protected]/org.eclipse.jetty.compression.gzip.internal.GzipDecoderSource.release(GzipDecoderSource.java:277)
	at [email protected]/org.eclipse.jetty.io.content.ContentSourceTransformer.read(ContentSourceTransformer.java:77)
	at [email protected]/org.eclipse.jetty.compression.gzip.GzipDecoderSourceTest.testTransformerBug(GzipDecoderSourceTest.java:44)
	at java.base/java.lang.reflect.Method.invoke(Method.java:569)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
	at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
@lorban lorban added the Bug For general bugs on Jetty side label Mar 4, 2025
@lorban
Copy link
Contributor Author

lorban commented Mar 4, 2025

@joakime WDYT?

@joakime
Copy link
Contributor

joakime commented Mar 4, 2025

Yeah, seems like a bug in the release behavior.

lorban added a commit that referenced this issue Mar 5, 2025
… called and make sure release() is only called once

Signed-off-by: Ludovic Orban <[email protected]>
lorban added a commit that referenced this issue Mar 5, 2025
Signed-off-by: Ludovic Orban <[email protected]>
@lorban lorban self-assigned this Mar 5, 2025
@lorban lorban moved this to 🏗 In progress in Jetty 12.1.0 Mar 5, 2025
lorban added a commit that referenced this issue Mar 6, 2025
Signed-off-by: Ludovic Orban <[email protected]>
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: 🏗 In progress
2 participants