lhotari commented on code in PR #19270:
URL: https://github.com/apache/pulsar/pull/19270#discussion_r1082536276


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java:
##########
@@ -965,15 +961,23 @@ protected void handleConnect(CommandConnect connect) {
                         remoteAddress, originalPrincipal);
                 }
             }
+            if (service.isAuthorizationEnabled()) {
+                validateRoleAndOriginalPrincipal();
+            }
         } catch (Exception e) {
-            service.getPulsarStats().recordConnectionCreateFail();
             logAuthException(remoteAddress, "connect", getPrincipal(), 
Optional.empty(), e);
-            String msg = "Unable to authenticate";
-            writeAndFlush(Commands.newError(-1, 
ServerError.AuthenticationError, msg));
-            close();
+            closeForAuthenticationError();
         }
     }
 
+    private void closeForAuthenticationError() {
+        state = State.Failed;
+        service.getPulsarStats().recordConnectionCreateFail();
+        String msg = "Unable to authenticate";
+        writeAndFlush(Commands.newError(-1, ServerError.AuthenticationError, 
msg));
+        close();

Review Comment:
   It's already like this in the original code, but I'd assume that 
`ctx.writeAndFlush(...).addListener(ChannelFutureListener.CLOSE);` (or 
`org.apache.pulsar.common.util.netty.NettyChannelUtil.writeAndFlushWithClosePromise`)
 should be used so that the channel doesn't get closed before the error has 
been written to the channel.
   
   
https://github.com/apache/pulsar/blob/d6fcdb8e1e192e0d9e2fbe6307d273b27ed2930f/pulsar-common/src/main/java/org/apache/pulsar/common/util/netty/NettyChannelUtil.java#L59-L61



-- 
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]

Reply via email to