chengxilo commented on code in PR #3652:
URL: https://github.com/apache/iggy/pull/3652#discussion_r3575714411


##########
foreign/go/client/tcp/tcp_session_management.go:
##########
@@ -30,41 +30,42 @@ import (
 )
 
 func (c *IggyTcpClient) LoginUser(ctx context.Context, username string, 
password string) (*iggcon.IdentityInfo, error) {
-       c.logger.Info("Iggy client is signing in...", 
slog.String("client_address", c.clientAddress))
-       buffer, err := c.do(ctx, &command.LoginUser{
+       return c.login(ctx, &command.LoginUser{
                Username: username,
                Password: password,
        })
-       if err != nil {
-               return nil, err
-       }
-
-       c.logger.Info("Iggy client has signed in successfully.", 
slog.String("client_address", c.clientAddress))
-       identity := binaryserialization.DeserializeLogInResponse(buffer)
-       shouldRedirect, err := c.HandleLeaderRedirection(ctx)
-       if err != nil {
-               return nil, err
-       }
-       if shouldRedirect {
-               if err = c.Connect(ctx); err != nil {
-                       return nil, err
-               }
-               return c.LoginUser(ctx, username, password)
-       }
-       return identity, nil
 }
 
 func (c *IggyTcpClient) LoginWithPersonalAccessToken(ctx context.Context, 
token string) (*iggcon.IdentityInfo, error) {
-       c.logger.Info("Iggy client is signing in...", 
slog.String("client_address", c.clientAddress))
-       buffer, err := c.do(ctx, &command.LoginWithPersonalAccessToken{
+       return c.login(ctx, &command.LoginWithPersonalAccessToken{
                Token: token,
        })
+}
+
+func (c *IggyTcpClient) login(ctx context.Context, loginCmd command.Command) 
(*iggcon.IdentityInfo, error) {
+       c.logger.Info("Iggy client is signing in...", 
slog.String("client_address", c.clientAddress))
+       c.mtx.Lock()
+       pre := c.sessionState
+       c.sessionState = iggcon.SessionStateAuthenticating
+       c.mtx.Unlock()
+
+       buffer, err := c.do(ctx, loginCmd)
        if err != nil {
+               // A rejected login leaves the session state untouched, so 
restore the
+               // pre-login state only while it is still Authenticating: if 
the state
+               // moved, the connection may died mid-attempt and invalidation 
already
+               // recorded it unauthenticated, skip the restoration.
+               c.mtx.Lock()
+               if c.sessionState == iggcon.SessionStateAuthenticating {

Review Comment:
   Yeah makes sense. I will drop it. I should not consider add an 
authenticating status just because I want to map with connecting status.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to