315157973 commented on a change in pull request #10754:
URL: https://github.com/apache/pulsar/pull/10754#discussion_r642586176



##########
File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
##########
@@ -243,6 +244,23 @@ public ServerCnx(PulsarService pulsar) {
         this.maxPendingBytesPerThread = 
conf.getMaxMessagePublishBufferSizeInMB() * 1024L * 1024L
                 / conf.getNumIOThreads();
         this.resumeThresholdPendingBytesPerThread = 
this.maxPendingBytesPerThread / 2;
+        this.connectionsLimiter = new ConnectionsLimiter(conf);
+    }
+
+    @Override
+    public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
+        if 
(!connectionsLimiter.increaseConnection(ctx.channel().remoteAddress())) {
+            ctx.channel().close();
+            log.info("Reached the maximum number of connections {}", 
remoteAddress);
+            return;
+        }
+        ctx.fireChannelRegistered();
+    }
+
+    @Override
+    public void channelUnregistered(ChannelHandlerContext ctx) throws 
Exception {
+        connectionsLimiter.decreaseConnection(ctx.channel().remoteAddress());
+        ctx.fireChannelRegistered();

Review comment:
       Good catch!




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to