jinmeiliao commented on a change in pull request #7416:
URL: https://github.com/apache/geode/pull/7416#discussion_r827193959



##########
File path: 
geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/MessageDispatcher.java
##########
@@ -432,34 +442,38 @@ protected void runDispatcher() {
           _messageQueue.remove();
           clientMessage = null;
         } catch (AuthenticationExpiredException expired) {
-          if (waitForReAuthenticationStartTime == -1) {
-            waitForReAuthenticationStartTime = System.currentTimeMillis();
-            // only send the message to clients who can handle the message
-            if 
(getProxy().getVersion().isNewerThanOrEqualTo(RE_AUTHENTICATION_START_VERSION)) 
{
-              EventID eventId = createEventId();
-              sendMessageDirectly(new ClientReAuthenticateMessage(eventId));
+          // only send the message to clients who can handle the message
+          if 
(getProxy().getVersion().isNewerThanOrEqualTo(RE_AUTHENTICATION_START_VERSION)) 
{
+            EventID eventId = createEventId();
+            sendMessageDirectly(new ClientReAuthenticateMessage(eventId));
+          }
+
+          waitForReAuthenticationStartTime = System.currentTimeMillis();
+          long waitFinishTime = waitForReAuthenticationStartTime + 
reAuthenticateWaitTime;
+          // We wait for all versions of clients to re-authenticate. For older 
clients we still
+          // wait, just in case client will perform some operations to
+          // trigger credential refresh on its own.
+          synchronized (re_auth_lock) {
+            subjectUpdated = false;
+            long remainingWaitTime = waitFinishTime - 
System.currentTimeMillis();
+            while (!subjectUpdated && remainingWaitTime > 0) {
+              re_auth_lock.wait(remainingWaitTime);
+              remainingWaitTime = waitFinishTime - System.currentTimeMillis();
             }
-            // We wait for all versions of clients to re-authenticate. For 
older clients we still
-            // wait, just in case client will perform some operations to
-            // trigger credential refresh on its own.
-            Thread.sleep(200);
-          } else {
+          }
+          // the above wait timed out
+          if (!subjectUpdated) {
             long elapsedTime = System.currentTimeMillis() - 
waitForReAuthenticationStartTime;
-            if (elapsedTime > reAuthenticateWaitTime) {
-              // reset the timer here since we are no longer waiting for 
re-auth to happen anymore
-              waitForReAuthenticationStartTime = -1;
-              synchronized (_stopDispatchingLock) {
-                logger.warn("Client did not re-authenticate back successfully 
in " + elapsedTime
-                    + "ms. Unregister this client proxy.");
-                pauseOrUnregisterProxy(expired);
-              }
+            // reset the timer here since we are no longer waiting for re-auth 
to happen anymore
+            waitForReAuthenticationStartTime = -1;
+            synchronized (_stopDispatchingLock) {
+              logger.warn("Client did not re-authenticate back successfully in 
" + elapsedTime
+                  + "ms. Unregister this client proxy.");

Review comment:
       good point.

##########
File path: 
geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/MessageDispatcher.java
##########
@@ -432,34 +442,38 @@ protected void runDispatcher() {
           _messageQueue.remove();
           clientMessage = null;
         } catch (AuthenticationExpiredException expired) {
-          if (waitForReAuthenticationStartTime == -1) {
-            waitForReAuthenticationStartTime = System.currentTimeMillis();
-            // only send the message to clients who can handle the message
-            if 
(getProxy().getVersion().isNewerThanOrEqualTo(RE_AUTHENTICATION_START_VERSION)) 
{
-              EventID eventId = createEventId();
-              sendMessageDirectly(new ClientReAuthenticateMessage(eventId));
+          // only send the message to clients who can handle the message
+          if 
(getProxy().getVersion().isNewerThanOrEqualTo(RE_AUTHENTICATION_START_VERSION)) 
{
+            EventID eventId = createEventId();
+            sendMessageDirectly(new ClientReAuthenticateMessage(eventId));
+          }
+
+          waitForReAuthenticationStartTime = System.currentTimeMillis();
+          long waitFinishTime = waitForReAuthenticationStartTime + 
reAuthenticateWaitTime;

Review comment:
       done

##########
File path: 
geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/MessageDispatcher.java
##########
@@ -193,6 +194,15 @@ public boolean isWaitingForReAuthentication() {
     return waitForReAuthenticationStartTime > 0;
   }
 
+  private volatile boolean subjectUpdated = false;
+
+  public void notifyReAuthentication() {
+    synchronized (re_auth_lock) {
+      subjectUpdated = true;
+      re_auth_lock.notify();

Review comment:
       done

##########
File path: 
geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/MessageDispatcher.java
##########
@@ -113,6 +113,7 @@
   private volatile boolean _isStopped = true;
 
   private volatile long waitForReAuthenticationStartTime = -1;
+  private final Object re_auth_lock = new Object();

Review comment:
       done




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