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 memory leak in HttpPostRequestDecoder when body is empty #14760

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.ByteBufInputStream;
import io.netty.buffer.ByteBufOutputStream;
import io.netty.buffer.Unpooled;
import io.netty.buffer.UnpooledByteBufAllocator;
import io.netty.handler.codec.http.DefaultFullHttpRequest;
import io.netty.handler.codec.http.DefaultHttpHeaders;
Expand Down Expand Up @@ -169,7 +168,7 @@ public static HttpPostRequestDecoder createPostRequestDecoder(
inputStream.mark(Integer.MAX_VALUE);
}
if (inputStream.available() == 0) {
data = Unpooled.EMPTY_BUFFER;
return null;
} else {
data = HEAP_ALLOC.buffer();
ByteBufOutputStream os = new ByteBufOutputStream(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import org.apache.dubbo.rpc.protocol.tri.rest.test.BaseServiceTest
import org.apache.dubbo.rpc.protocol.tri.test.TestRequest
import org.apache.dubbo.rpc.protocol.tri.test.TestRunnerBuilder

import io.netty.buffer.AbstractByteBuf
import io.netty.util.ResourceLeakDetector

class RestProtocolTest extends BaseServiceTest {

@Override
Expand Down Expand Up @@ -174,18 +177,28 @@ class RestProtocolTest extends BaseServiceTest {
'/argTest' | 'Sam is 8 years old'
}

@SuppressWarnings('GroovyAccessibility')
def "urlEncodeForm body test"() {
given:
def level = ResourceLeakDetector.level
def leaks = AbstractByteBuf.leakDetector.allLeaks
ResourceLeakDetector.level = ResourceLeakDetector.Level.PARANOID
leaks.clear()
and:
def request = new TestRequest(
path: path,
contentType: MediaType.APPLICATION_FROM_URLENCODED,
body: body
)
expect:
runner.post(request) == output
leaks.empty
cleanup:
ResourceLeakDetector.level = level
where:
path | body | output
'/argTest' | 'name=Sam&age=8' | 'Sam is 8 years old'
'/argTest' | '' | 'null is 0 years old'
}

def "override mapping test"() {
Expand Down
Loading