This is an automated email from the ASF dual-hosted git repository.

mmarshall pushed a commit to branch branch-2.10
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/branch-2.10 by this push:
     new f9e24f2daf5 [fix][proxy] Only go to connecting state once (#19331)
f9e24f2daf5 is described below

commit f9e24f2daf5de161b7d98220e790046acc63bb00
Author: Michael Marshall <[email protected]>
AuthorDate: Tue Jan 31 13:31:08 2023 -0600

    [fix][proxy] Only go to connecting state once (#19331)
    
    Relates to: 
https://github.com/apache/pulsar/pull/17831#discussion_r1080836860
    
    ### Motivation
    
    When the `ProxyConnection` handles a `Connect` command, that is the time to 
go to `Connecting` state. There is no other time that makes sense to switch to 
connecting. The current logic will go to connecting in certain 
re-authentication scenarios, but those are incorrect. By moving the state 
change to earlier in the logic, we make the state transition clearer and 
prevent corrupted state.
    
    ### Modifications
    
    * Remove `state = State.Connecting` from the `doAuthentication` method, 
which is called multiple times for various reasons
    * Add `state = State.Connecting` to the start of the `handleConnect` method.
    
    ### Verifying this change
    
    The existing tests will verify this change, and reading through the code 
makes it clear this is a correct change.
    
    ### Does this pull request potentially affect one of the following parts:
    
    Not a breaking change.
    
    ### Documentation
    
    - [x] `doc-not-needed`
    
    It would be nice to map out the state transitions for our connection 
classes. That is our of the scope of this small improvement.
    
    ### Matching PR in forked repository
    
    PR in forked repository: https://github.com/michaeljmarshall/pulsar/pull/21
    
    (cherry picked from commit c8650cef83f558d3942b4c2f5e23c7d0df9eed40)
---
 .../src/main/java/org/apache/pulsar/proxy/server/ProxyConnection.java   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git 
a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyConnection.java
 
b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyConnection.java
index a01e3bce02d..be5943e49c8 100644
--- 
a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyConnection.java
+++ 
b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyConnection.java
@@ -398,12 +398,12 @@ public class ProxyConnection extends PulsarHandler {
             LOG.debug("[{}] Authentication in progress client by method {}.",
                     remoteAddress, authMethod);
         }
-        state = State.Connecting;
     }
 
     @Override
     protected void handleConnect(CommandConnect connect) {
         checkArgument(state == State.Init);
+        state = State.Connecting;
         this.setRemoteEndpointProtocolVersion(connect.getProtocolVersion());
         this.hasProxyToBrokerUrl = connect.hasProxyToBrokerUrl();
         this.protocolVersionToAdvertise = 
getProtocolVersionToAdvertise(connect);

Reply via email to