Revert "Use releaseOnClose to release the ByteBuf when the output stream is c…" (#14294)

This reverts commit b831c26e83.
This commit is contained in:
TomlongTK 2024-06-06 20:03:55 +08:00 committed by GitHub
parent b831c26e83
commit 64264f6c46
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 24 additions and 2 deletions

View File

@ -18,8 +18,11 @@ 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;
@ -32,4 +35,12 @@ 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,8 +16,11 @@
*/
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;
@ -42,6 +45,14 @@ 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(), true));
return new Http1OutputMessage(new ByteBufOutputStream(channel.alloc().buffer()));
}
@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, true);
ByteBufOutputStream outputStream = new ByteBufOutputStream(buffer);
return new Http2OutputMessageFrame(outputStream, endStream);
}