Skip to content

Commit

Permalink
allow expiration timer logic to be called unlocked
Browse files Browse the repository at this point in the history
This ensures the logic that triggers user disconnections
share the same code paths and sets the same variables

Signed-off-by: R.I.Pienaar <rip@devco.net>
  • Loading branch information
ripienaar committed Dec 2, 2022
1 parent 14f40b9 commit e6c78f1
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions server/client.go
Expand Up @@ -843,7 +843,7 @@ func (c *client) RegisterUser(user *User) {

// if a deadline time stamp is set we start a timer to disconnect the user at that time
if !user.ConnectionDeadline.IsZero() {
c.atmr = time.AfterFunc(time.Until(user.ConnectionDeadline), c.authExpired)
c.setExpirationTimerUnlocked(time.Until(user.ConnectionDeadline))
}

c.mu.Unlock()
Expand Down Expand Up @@ -4711,12 +4711,17 @@ func (c *client) awaitingAuth() bool {
// We will lock on entry.
func (c *client) setExpirationTimer(d time.Duration) {
c.mu.Lock()
c.setExpirationTimerUnlocked(d)
c.mu.Unlock()
}

// This will set the atmr for the JWT expiration time. client lock should be held before call
func (c *client) setExpirationTimerUnlocked(d time.Duration) {
c.atmr = time.AfterFunc(d, c.authExpired)
// This is an JWT expiration.
if c.flags.isSet(connectReceived) {
c.expires = time.Now().Add(d).Truncate(time.Second)
}
c.mu.Unlock()
}

// Return when this client expires via a claim, or 0 if not set.
Expand Down

0 comments on commit e6c78f1

Please sign in to comment.