This is an automated email from the ASF dual-hosted git repository.
mmarshall pushed a commit to branch branch-2.11
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/branch-2.11 by this push:
new 0271cd9db9b [fix][proxy] Only go to connecting state once (#19331)
0271cd9db9b is described below
commit 0271cd9db9bb2d9fef01162b956ab6219342377a
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 30d36446ccd..57ea60e9f19 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 @@ 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);