From 0271cd9db9bb2d9fef01162b956ab6219342377a Mon Sep 17 00:00:00 2001 From: Michael Marshall Date: Tue, 31 Jan 2023 13:31:08 -0600 Subject: [PATCH] [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) --- .../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 30d36446ccd0e..57ea60e9f1944 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 @@ -440,12 +440,12 @@ private void doAuthentication(AuthData clientData) 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);