mattisonchao commented on code in PR #17167:
URL: https://github.com/apache/pulsar/pull/17167#discussion_r955614920
##########
pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyConnection.java:
##########
@@ -144,22 +146,29 @@ public ProxyConnection(ProxyService proxyService,
DnsAddressResolverGroup dnsAdd
this.dnsAddressResolverGroup = dnsAddressResolverGroup;
this.state = State.Init;
this.brokerProxyValidator = service.getBrokerProxyValidator();
+ this.connectionController = proxyService.getConnectionController();
}
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
super.channelRegistered(ctx);
ProxyService.ACTIVE_CONNECTIONS.inc();
- if (ProxyService.ACTIVE_CONNECTIONS.get() >
service.getConfiguration().getMaxConcurrentInboundConnections()) {
- state = State.Closing;
- ctx.close();
+ SocketAddress rmAddress = ctx.channel().remoteAddress();
+ ConnectionController.State state =
connectionController.increaseConnection(rmAddress);
+ if (!state.equals(ConnectionController.State.OK)) {
+ ctx.channel().writeAndFlush(Commands.newError(-1,
ServerError.NotAllowedError,
+
state.equals(ConnectionController.State.REACH_MAX_CONNECTION)
+ ? "Reached the maximum number of connections"
+ : "Reached the maximum number of connections on
address" + rmAddress));
+ ctx.channel().close();
Review Comment:
Applied.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]