You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2023/03/06 07:26:40 UTC
[dubbo] branch 3.1 updated: Fix issue 11708 (#11714)
This is an automated email from the ASF dual-hosted git repository.
albumenj pushed a commit to branch 3.1
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.1 by this push:
new a21d04255a Fix issue 11708 (#11714)
a21d04255a is described below
commit a21d04255a9aae791b526a43c560b9645d063b18
Author: Mengyang Tang <me...@163.com>
AuthorDate: Mon Mar 6 15:26:15 2023 +0800
Fix issue 11708 (#11714)
---
.../java/org/apache/dubbo/qos/pu/TelnetDetector.java | 19 ++++++++++++-------
.../apache/dubbo/remoting/buffer/ChannelBuffer.java | 8 ++++++++
.../dubbo/remoting/buffer/DynamicChannelBuffer.java | 5 +++++
.../transport/netty4/NettyBackedChannelBuffer.java | 6 ++++++
4 files changed, 31 insertions(+), 7 deletions(-)
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/pu/TelnetDetector.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/pu/TelnetDetector.java
index 84199937d4..a7b7c47ff7 100644
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/pu/TelnetDetector.java
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/pu/TelnetDetector.java
@@ -32,7 +32,7 @@ import static java.lang.Math.min;
public class TelnetDetector implements ProtocolDetector {
- private FrameworkModel frameworkModel;
+ private final FrameworkModel frameworkModel;
private final int MaxSize = 2048;
private final ChannelBuffer AytPreface = new HeapChannelBuffer(new byte[]{(byte) 0xff, (byte) 0xf6});
@@ -46,7 +46,7 @@ public class TelnetDetector implements ProtocolDetector {
return Result.UNRECOGNIZED;
}
Result resCommand = commandDetect(in);
- if (resCommand.equals(Result.RECOGNIZED)){
+ if (resCommand.equals(Result.RECOGNIZED)) {
return resCommand;
}
Result resAyt = telnetAytDetect(in);
@@ -62,14 +62,19 @@ public class TelnetDetector implements ProtocolDetector {
private Result commandDetect(ChannelBuffer in) {
// detect if remote channel send a qos command to server
ChannelBuffer back = in.copy();
- byte[] backBytes = new byte[back.readableBytes()];
- back.getBytes(back.readerIndex(), backBytes);
+ byte[] backBytes;
+ try {
+ backBytes = new byte[back.readableBytes()];
+ back.getBytes(back.readerIndex(), backBytes);
+ } finally {
+ back.release();
+ }
String s = new String(backBytes, CharsetUtil.UTF_8);
// trim /r/n to let parser work for input
s = s.trim();
CommandContext commandContext = TelnetCommandDecoder.decode(s);
- if(frameworkModel.getExtensionLoader(BaseCommand.class).hasExtension(commandContext.getCommandName())){
+ if (frameworkModel.getExtensionLoader(BaseCommand.class).hasExtension(commandContext.getCommandName())) {
return Result.RECOGNIZED;
}
return Result.UNRECOGNIZED;
@@ -79,10 +84,10 @@ public class TelnetDetector implements ProtocolDetector {
// detect if remote channel send a telnet ayt command to server
int prefaceLen = AytPreface.readableBytes();
int bytesRead = min(in.readableBytes(), prefaceLen);
- if(bytesRead == 0 || !ChannelBuffers.prefixEquals(in, AytPreface, bytesRead)) {
+ if (bytesRead == 0 || !ChannelBuffers.prefixEquals(in, AytPreface, bytesRead)) {
return Result.UNRECOGNIZED;
}
- if(bytesRead == prefaceLen) {
+ if (bytesRead == prefaceLen) {
// we need to consume preface because it's not a qos command
// consume and remember to mark, pu server handler reset reader index
in.readBytes(AytPreface.readableBytes());
diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/buffer/ChannelBuffer.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/buffer/ChannelBuffer.java
index fab35dd80e..e77cf46ab2 100644
--- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/buffer/ChannelBuffer.java
+++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/buffer/ChannelBuffer.java
@@ -948,4 +948,12 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* array
*/
int arrayOffset();
+
+ /**
+ * If this buffer is backed by an NIO direct buffer,
+ * in some scenarios it may be necessary to manually release.
+ */
+ default void release() {
+
+ }
}
diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/buffer/DynamicChannelBuffer.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/buffer/DynamicChannelBuffer.java
index dbd9677a76..cfd7965ffe 100644
--- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/buffer/DynamicChannelBuffer.java
+++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/buffer/DynamicChannelBuffer.java
@@ -200,4 +200,9 @@ public class DynamicChannelBuffer extends AbstractChannelBuffer {
public int arrayOffset() {
return buffer.arrayOffset();
}
+
+ @Override
+ public void release() {
+ buffer.release();
+ }
}
diff --git a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyBackedChannelBuffer.java b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyBackedChannelBuffer.java
index a64a646721..fd1f9c7c52 100644
--- a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyBackedChannelBuffer.java
+++ b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyBackedChannelBuffer.java
@@ -22,6 +22,7 @@ import org.apache.dubbo.remoting.buffer.ChannelBufferFactory;
import org.apache.dubbo.remoting.buffer.ChannelBuffers;
import io.netty.buffer.ByteBuf;
+import io.netty.util.ReferenceCountUtil;
import java.io.IOException;
import java.io.InputStream;
@@ -447,4 +448,9 @@ public class NettyBackedChannelBuffer implements ChannelBuffer {
public int compareTo(ChannelBuffer o) {
return ChannelBuffers.compare(this, o);
}
+
+ @Override
+ public void release() {
+ ReferenceCountUtil.safeRelease(buffer);
+ }
}