Skip to content

Commit

Permalink
Fix the time check logic for judging stale client channels to be inac…
Browse files Browse the repository at this point in the history
### What changes are proposed in this pull request?

Fix bug involved by #18332.
Alter the time judgment logic for judging whether stale client channels are inactive. Using the LocaTime object cannot correctly judge whether a channel client is inactive, because a LocalTime plus or minus time offset only changes the hour, minute, second attribute value, and It will not affect the date, you actually need to use the LocalDateTime object instead.
### Why are the changes needed?

Please clarify why the changes are needed. For instance,
In the code, the LocaTime class is used to determine that a client channel is inactive. The LocalTime object adds or subtracts the time offset. It only changes the hour, minute and second attribute value and does not affect the date. In fact, you need to use the LocalDateTime object.  In other words, the three-day certification cycle judgment should be based on date and time, not just time.

### Does this PR introduce any user facing changes?

Please list the user-facing changes introduced by your change, including
None

			pr-link: #18340
			change-id: cid-5b69e0c87d3bad8556ae27d491f3e0dc567378b9
  • Loading branch information
liuxiaohu9527 authored Oct 31, 2023
1 parent 32f675f commit 660e00d
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -160,12 +161,12 @@ public void close() {
* stale.
*/
private void cleanupStaleClients() {
LocalTime cleanupTime = LocalTime.now();
LocalDateTime cleanupTime = LocalDateTime.now();
LOG.debug("Starting cleanup authentication registry at {}", cleanupTime);
// Get a list of stale clients under read lock.
List<UUID> staleChannels = new ArrayList<>();
for (Map.Entry<UUID, AuthenticatedChannelInfo> clientEntry : mChannels.entrySet()) {
LocalTime lat = clientEntry.getValue().getLastAccessTime();
LocalDateTime lat = clientEntry.getValue().getLastAccessTime();
if (lat.plusSeconds(mCleanupIntervalMs / 1000).isBefore(cleanupTime)) {
staleChannels.add(clientEntry.getKey());
}
Expand Down Expand Up @@ -201,7 +202,7 @@ protected void checkSupported(AuthType authType) {
* and Sasl objects per channel.
*/
class AuthenticatedChannelInfo {
private LocalTime mLastAccessTime;
private LocalDateTime mLastAccessTime;
private AuthenticatedUserInfo mUserInfo;
private AuthenticatedChannelServerDriver mSaslServerDriver;

Expand All @@ -213,17 +214,17 @@ public AuthenticatedChannelInfo(AuthenticatedUserInfo userInfo,
AuthenticatedChannelServerDriver saslServerDriver) {
mUserInfo = userInfo;
mSaslServerDriver = saslServerDriver;
mLastAccessTime = LocalTime.now();
mLastAccessTime = LocalDateTime.now();
}

private synchronized void updateLastAccessTime() {
mLastAccessTime = LocalTime.now();
mLastAccessTime = LocalDateTime.now();
}

/**
* @return the last access time
*/
public synchronized LocalTime getLastAccessTime() {
public synchronized LocalDateTime getLastAccessTime() {
return mLastAccessTime;
}

Expand Down

0 comments on commit 660e00d

Please sign in to comment.