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

🐛 Don't call session logout for keepAliveHandler #1949

Merged
merged 1 commit into from
Jul 18, 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
28 changes: 11 additions & 17 deletions pkg/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,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 @@ -215,7 +220,8 @@ func newClient(ctx context.Context, logger logr.Logger, sessionKey string, url *
_, err := methods.GetCurrentTime(ctx, vimClient)
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 @@ -228,18 +234,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 @@ -253,8 +247,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")
})
}
Expand Down