Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-1.5] 🐛 Don't call session logout for keepAliveHandler #2035

Merged
merged 1 commit into from
Jul 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 11 additions & 23 deletions pkg/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,14 @@ func GetOrCreate(ctx context.Context, params *Params) (*Session, error) {
logger.V(2).Info("found active cached vSphere client session")
return s, nil
}
}

clearCache(logger, sessionKey)
logger.V(2).Info("logout the session because it is inactive")
if err := s.Client.Logout(ctx); err != nil {
logger.Error(err, "unable to logout session")
} else {
logger.Info("logout session succeed")
}
}

// soap.ParseURL expects a valid URL. In the case of a bare, unbracketed
// IPv6 address (e.g fd00::1) ParseURL will fail. Surround unbracketed IPv6
Expand Down Expand Up @@ -206,16 +211,11 @@ func newClient(ctx context.Context, logger logr.Logger, sessionKey string, url *
}

vimClient.RoundTripper = session.KeepAliveHandler(vimClient.RoundTripper, feature.KeepAliveDuration, func(tripper soap.RoundTripper) error {
// we tried implementing
// c.Login here but the client once logged out
// keeps errong in invalid username or password
// we tried with cached username and password in session still the error persisted
// hence we just clear the cache and expect the client to
// be recreated in next GetOrCreate call
_, err := methods.GetCurrentTime(ctx, tripper)
if err != nil {
logger.Error(err, "failed to keep alive govmomi client")
clearCache(logger, sessionKey)
logger.Info("clearing the session", "key", sessionKey)
sessionCache.Delete(sessionKey)
}
return err
})
Expand All @@ -227,18 +227,6 @@ func newClient(ctx context.Context, logger logr.Logger, sessionKey string, url *
return c, nil
}

func clearCache(logger logr.Logger, sessionKey string) {
if cachedSession, ok := sessionCache.Load(sessionKey); ok {
s := cachedSession.(*Session)

logger.Info("performing session log out and clearing session", "key", sessionKey)
if err := s.Logout(context.Background()); err != nil {
logger.Error(err, "unable to logout session")
}
}
sessionCache.Delete(sessionKey)
}

// newManager creates a Manager that encompasses the REST Client for the VSphere tagging API.
func newManager(ctx context.Context, logger logr.Logger, sessionKey string, client *vim25.Client, user *url.Userinfo, feature Feature) (*tags.Manager, error) {
rc := rest.NewClient(client)
Expand All @@ -251,8 +239,8 @@ func newManager(ctx context.Context, logger logr.Logger, sessionKey string, clie
return nil
}

logger.Info("rest client session expired, clearing cache")
clearCache(logger, sessionKey)
logger.Info("rest client session expired, clearing session", "key", sessionKey)
sessionCache.Delete(sessionKey)
return errors.New("rest client session expired")
})
if err := rc.Login(ctx, user); err != nil {
Expand Down