michaeljmarshall commented on code in PR #19292:
URL: https://github.com/apache/pulsar/pull/19292#discussion_r1086821101


##########
pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyConnection.java:
##########
@@ -423,31 +421,65 @@ public void brokerConnected(DirectProxyHandler 
directProxyHandler, CommandConnec
     // According to auth result, send newConnected or newAuthChallenge command.
     private void doAuthentication(AuthData clientData)
             throws Exception {
-        AuthData brokerData = authState.authenticate(clientData);
-        // authentication has completed, will send newConnected command.
-        if (authState.isComplete()) {
-            clientAuthRole = authState.getAuthRole();
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("[{}] Client successfully authenticated with {} role 
{}",
-                        remoteAddress, authMethod, clientAuthRole);
+        CompletableFuture<AuthData> authChallengeFuture = 
authState.authenticateAsync(clientData);
+        if (authChallengeFuture.isDone()) {
+            if (!authChallengeFuture.isCompletedExceptionally()) {
+                authChallengeSuccessCallback(authChallengeFuture.get());
+            } else {
+                try {

Review Comment:
   I wrote it this way because most `AuthenticationProvider` implementations 
are synchronous, and I was optimizing for the case where the future will always 
be completed. The `whenComplete` method incurs additional object creation and 
adding to a queue before executing right away. If you think this is a premature 
optimization, I can collapse the branches of this `if`.



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