tisonkun commented on code in PR #20595:
URL: https://github.com/apache/pulsar/pull/20595#discussion_r1244802629
##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConnectionHandler.java:
##########
@@ -66,20 +67,21 @@ protected void grabCnx() {
return;
}
- synchronized (this) {
- if (duringConnect) {
- log.info("[{}] [{}] Skip grabbing the connection since there
is a pending connection",
- state.topic, state.getHandlerName());
- return;
- }
- if (isValidStateForReconnection()) {
- duringConnect = true;
- } else {
- // Ignore connection closed when we are shutting down
- log.info("[{}] [{}] Ignoring reconnection request (state: {})",
- state.topic, state.getHandlerName(), state.getState());
+ if (duringConnect.get()) {
+ log.info("[{}] [{}] Skip grabbing the connection since there is a
pending connection",
+ state.topic, state.getHandlerName());
+ return;
+ }
+ if (isValidStateForReconnection()) {
+ if (!duringConnect.compareAndSet(false, true)) {
Review Comment:
nit: avoid `!` and swap the block - my experience is that double negative
predicts are brittle.
N.B. "nit" means it's not a blocker to this patch but nice to have IMO.
--
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]