Parcourir la source

fix race condition

Jonathan Turner il y a 7 ans
Parent
commit
cf423494d5
2 fichiers modifiés avec 9 ajouts et 1 suppressions
  1. 2 1
      client/client_integration_test.go
  2. 7 0
      client/session.go

+ 2 - 1
client/client_integration_test.go

@@ -439,7 +439,8 @@ func TestMultiThreadedClientSession(t *testing.T) {
 			if err != nil {
 				t.Logf("error getting session: %v", err)
 			}
-			fmt.Fprintf(ioutil.Discard, "%v", s.renewTill)
+			_, _, _, r, _ := s.timeDetails()
+			fmt.Fprintf(ioutil.Discard, "%v", r)
 		}()
 		time.Sleep(time.Second)
 	}

+ 7 - 0
client/session.go

@@ -127,6 +127,13 @@ func (s *session) tgtDetails() (string, messages.Ticket, types.EncryptionKey) {
 	return s.realm, s.tgt, s.sessionKey
 }
 
+// timeDetails is a thread safe way to get the session's validity time values
+func (s *session) timeDetails() (string, time.Time, time.Time, time.Time, time.Time) {
+	s.mux.RLock()
+	defer s.mux.RUnlock()
+	return s.realm, s.authTime, s.endTime, s.renewTill, s.sessionKeyExpiration
+}
+
 // enableAutoSessionRenewal turns on the automatic renewal for the client's TGT session.
 func (cl *Client) enableAutoSessionRenewal(s *session) {
 	var timer *time.Timer