This is an automated email from the ASF dual-hosted git repository.
guohao pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.0 by this push:
new 5aa660ce1d Fix duplicate ssl init (#9959)
5aa660ce1d is described below
commit 5aa660ce1d5e4663494f0fddc15544369a22c93e
Author: GuoHao <[email protected]>
AuthorDate: Fri Apr 22 22:20:32 2022 +0800
Fix duplicate ssl init (#9959)
---
.../dubbo/remoting/api/PortUnificationServer.java | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git
a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/api/PortUnificationServer.java
b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/api/PortUnificationServer.java
index b28f428726..51125bda34 100644
---
a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/api/PortUnificationServer.java
+++
b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/api/PortUnificationServer.java
@@ -35,6 +35,7 @@ import io.netty.channel.ChannelPipeline;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.group.DefaultChannelGroup;
import io.netty.channel.socket.SocketChannel;
+import io.netty.handler.ssl.SslContext;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GlobalEventExecutor;
@@ -111,6 +112,13 @@ public class PortUnificationServer {
getUrl().getPositiveParameter(IO_THREADS_KEY,
Constants.DEFAULT_IO_THREADS),
EVENT_LOOP_WORKER_POOL_NAME);
+ final boolean enableSsl = getUrl().getParameter(SSL_ENABLED_KEY,
false);
+ final SslContext sslContext;
+ if (enableSsl) {
+ sslContext = SslContexts.buildServerSslContext(url);
+ } else {
+ sslContext = null;
+ }
bootstrap.group(bossGroup, workerGroup)
.channel(NettyEventLoopFactory.serverSocketChannelClass())
.option(ChannelOption.SO_REUSEADDR, Boolean.TRUE)
@@ -121,15 +129,9 @@ public class PortUnificationServer {
protected void initChannel(SocketChannel ch) throws Exception {
// Do not add idle state handler here, because it should
be added in the protocol handler.
final ChannelPipeline p = ch.pipeline();
- final boolean enableSsl =
getUrl().getParameter(SSL_ENABLED_KEY, false);
final PortUnificationServerHandler puHandler;
- if (enableSsl) {
- puHandler = new PortUnificationServerHandler(url,
- SslContexts.buildServerSslContext(url), true,
protocols, channels);
- } else {
- puHandler = new PortUnificationServerHandler(url,
null, false, protocols,
- channels);
- }
+ puHandler = new PortUnificationServerHandler(url,
sslContext, true, protocols,
+ channels);
p.addLast("negotiation-protocol", puHandler);
}
});