Skip to content

Commit 2af3a91

Browse files
committed
Merge branch 'apache-3.2' into apache-3.3
2 parents 6725e2d + a35af27 commit 2af3a91

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistryDirectory.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,17 @@ private void refreshInvoker(List<URL> invokerUrls) {
343343
return;
344344
}
345345

346+
int originSize = invokerUrls.size();
347+
invokerUrls = invokerUrls.stream().distinct().collect(Collectors.toList());
348+
if (invokerUrls.size() != originSize) {
349+
logger.info("Received duplicated invoker urls changed event from registry. "
350+
+ "Registry type: instance. "
351+
+ "Service Key: "
352+
+ getConsumerUrl().getServiceKey() + ". "
353+
+ "Notify Urls Size : " + originSize + ". "
354+
+ "Distinct Urls Size: " + invokerUrls.size() + ".");
355+
}
356+
346357
// use local reference to avoid NPE as this.urlInvokerMap will be set null concurrently at
347358
// destroyAllInvokers().
348359
Map<ProtocolServiceKeyWithAddress, Invoker<T>> localUrlInvokerMap = this.urlInvokerMap;

dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,17 @@ private void refreshInvoker(List<URL> invokerUrls) {
310310
return;
311311
}
312312

313+
int originSize = invokerUrls.size();
314+
invokerUrls = invokerUrls.stream().distinct().collect(Collectors.toList());
315+
if (invokerUrls.size() != originSize) {
316+
logger.info("Received duplicated invoker urls changed event from registry. "
317+
+ "Registry type: interface. "
318+
+ "Service Key: "
319+
+ getConsumerUrl().getServiceKey() + ". "
320+
+ "Notify Urls Size : " + originSize + ". "
321+
+ "Distinct Urls Size: " + invokerUrls.size() + ".");
322+
}
323+
313324
// use local reference to avoid NPE as this.urlInvokerMap will be set null concurrently at
314325
// destroyAllInvokers().
315326
Map<URL, Invoker<T>> localUrlInvokerMap = this.urlInvokerMap;

dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyPortUnificationServerHandler.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.apache.dubbo.common.io.Bytes;
2121
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
2222
import org.apache.dubbo.common.logger.LoggerFactory;
23+
import org.apache.dubbo.common.ssl.AuthPolicy;
2324
import org.apache.dubbo.common.ssl.CertManager;
2425
import org.apache.dubbo.common.ssl.ProviderCert;
2526
import org.apache.dubbo.remoting.ChannelHandler;
@@ -47,6 +48,7 @@
4748
import io.netty.handler.ssl.SslHandshakeCompletionEvent;
4849
import io.netty.util.AttributeKey;
4950

51+
import static org.apache.dubbo.common.constants.LoggerCodeConstants.CONFIG_SSL_CONNECT_INSECURE;
5052
import static org.apache.dubbo.common.constants.LoggerCodeConstants.INTERNAL_ERROR;
5153

5254
public class NettyPortUnificationServerHandler extends ByteToMessageDecoder {
@@ -122,8 +124,27 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) t
122124
ProviderCert providerConnectionConfig =
123125
certManager.getProviderConnectionConfig(url, ctx.channel().remoteAddress());
124126

125-
if (providerConnectionConfig != null && isSsl(in)) {
126-
enableSsl(ctx, providerConnectionConfig);
127+
if (providerConnectionConfig != null && canDetectSsl(in)) {
128+
if (isSsl(in)) {
129+
enableSsl(ctx, providerConnectionConfig);
130+
} else {
131+
// check server should load TLS or not
132+
if (providerConnectionConfig.getAuthPolicy() != AuthPolicy.NONE) {
133+
byte[] preface = new byte[in.readableBytes()];
134+
in.readBytes(preface);
135+
LOGGER.error(
136+
CONFIG_SSL_CONNECT_INSECURE,
137+
"client request server without TLS",
138+
"",
139+
String.format(
140+
"Downstream=%s request without TLS preface, but server require it. " + "preface=%s",
141+
ctx.channel().remoteAddress(), Bytes.bytes2hex(preface)));
142+
143+
// Untrusted connection; discard everything and close the connection.
144+
in.clear();
145+
ctx.close();
146+
}
147+
}
127148
} else {
128149
detectProtocol(ctx, url, channel, in);
129150
}
@@ -150,6 +171,11 @@ protected void configurePipeline(ChannelHandlerContext ctx, String protocol) thr
150171
p.remove(this);
151172
}
152173

174+
private boolean canDetectSsl(ByteBuf buf) {
175+
// at least 5 bytes to determine if data is encrypted
176+
return detectSsl && buf.readableBytes() >= 5;
177+
}
178+
153179
private boolean isSsl(ByteBuf buf) {
154180
// at least 5 bytes to determine if data is encrypted
155181
if (detectSsl && buf.readableBytes() >= 5) {

0 commit comments

Comments
 (0)