Use releaseOnClose to release the ByteBuf when the output stream is closed (#14263)

This commit is contained in:
TomlongTK 2024-05-31 16:11:25 +08:00 committed by GitHub
parent 48df310ce7
commit b831c26e83
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 2 additions and 24 deletions

View File

@ -18,11 +18,8 @@ package org.apache.dubbo.remoting.http12.h1;
import org.apache.dubbo.remoting.http12.HttpOutputMessage;
import java.io.IOException;
import java.io.OutputStream;
import io.netty.buffer.ByteBufOutputStream;
public class Http1OutputMessage implements HttpOutputMessage {
private final OutputStream outputStream;
@ -35,12 +32,4 @@ public class Http1OutputMessage implements HttpOutputMessage {
public OutputStream getBody() {
return outputStream;
}
@Override
public void close() throws IOException {
if (outputStream instanceof ByteBufOutputStream) {
((ByteBufOutputStream) outputStream).buffer().release();
}
outputStream.close();
}
}

View File

@ -16,11 +16,8 @@
*/
package org.apache.dubbo.remoting.http12.h2;
import java.io.IOException;
import java.io.OutputStream;
import io.netty.buffer.ByteBufOutputStream;
public class Http2OutputMessageFrame implements Http2OutputMessage {
private final OutputStream body;
@ -45,14 +42,6 @@ public class Http2OutputMessageFrame implements Http2OutputMessage {
return body;
}
@Override
public void close() throws IOException {
if (body instanceof ByteBufOutputStream) {
((ByteBufOutputStream) body).buffer().release();
}
body.close();
}
@Override
public boolean isEndStream() {
return endStream;

View File

@ -52,7 +52,7 @@ public class NettyHttp1Channel implements HttpChannel {
@Override
public HttpOutputMessage newOutputMessage() {
return new Http1OutputMessage(new ByteBufOutputStream(channel.alloc().buffer()));
return new Http1OutputMessage(new ByteBufOutputStream(channel.alloc().buffer(), true));
}
@Override

View File

@ -57,7 +57,7 @@ public class NettyH2StreamChannel implements H2StreamChannel {
@Override
public Http2OutputMessage newOutputMessage(boolean endStream) {
ByteBuf buffer = http2StreamChannel.alloc().buffer();
ByteBufOutputStream outputStream = new ByteBufOutputStream(buffer);
ByteBufOutputStream outputStream = new ByteBufOutputStream(buffer, true);
return new Http2OutputMessageFrame(outputStream, endStream);
}