Repository: microsoft/garnet
File: libs/server/Resp/ACLCommands.cs (C#)

Code before:
                {
                    ops[i] = parseState.GetString(i);
                }

                try
                {
                    // Modify or create the user with the given username
                    var userHandle = aclAuthenticator.GetAccessControlList().GetUserHandle(username);

                    if (userHandle == null)
                    {
                        userHandle = new UserHandle(new User(username));

                        try
                        {
                            aclAuthenticator.GetAccessControlList().AddUserHandle(userHandle);
                        }
                        catch (ACLUserAlreadyExistsException)
                        {
                            // If AddUser failed, retrieve the concurrently created user
                            userHandle = aclAuthenticator.GetAccessControlList().GetUserHandle(username);
                        }
                    }

                    User newUser;
                    User effectiveUser;
                    do
                    {
                        // Modifications to user permissions must be performed against the effective user.
                        effectiveUser = userHandle.User;
                        newUser = new User(effectiveUser);

                        // Remaining parameters are ACL operations
                        for (var i = 1; i < ops.Length; i++)
                        {
                            ACLParser.ApplyACLOpToUser(ref newUser, ops[i]);
                        }

                    }
                    while (!userHandle.TrySetUser(newUser, effectiveUser));
                }
                catch (ACLException exception)
                {
                    // Abort command execution
                    while (!RespWriteUtils.TryWriteError($"ERR {exception.Message}", ref dcurr, dend))
                        SendAndReset();

                    return true;
                }

                while (!RespWriteUtils.TryWriteDirect(CmdStrings.RESP_OK, ref dcurr, dend))

Review comment (suggestion):
Rename to currentUser, so it is clear we are making a (conditional) atomic transition from `currentUser` -> `newUser`.

Code after:
                {
                    ops[i] = parseState.GetString(i);
                }

                try
                {
                    // Modify or create the user with the given username
                    var userHandle = aclAuthenticator.GetAccessControlList().GetUserHandle(username);

                    if (userHandle == null)
                    {
                        userHandle = new UserHandle(new User(username));

                        try
                        {
                            aclAuthenticator.GetAccessControlList().AddUserHandle(userHandle);
                        }
                        catch (ACLUserAlreadyExistsException)
                        {
                            // If AddUser failed, retrieve the concurrently created user
                            userHandle = aclAuthenticator.GetAccessControlList().GetUserHandle(username);
                        }
                    }

                    User newUser;
                    User currentUser;
                    do
                    {
                        // Modifications to user permissions must be performed against the effective user.
                        currentUser = userHandle.User;
                        newUser = new User(currentUser);

                        // Remaining parameters are ACL operations
                        for (var i = 1; i < ops.Length; i++)
                        {
                            ACLParser.ApplyACLOpToUser(ref newUser, ops[i]);
                        }

                    }
                    while (!userHandle.TrySetUser(newUser, currentUser));
                }
                catch (ACLException exception)
                {
                    // Abort command execution
                    while (!RespWriteUtils.TryWriteError($"ERR {exception.Message}", ref dcurr, dend))
                        SendAndReset();

                    return true;
                }

                while (!RespWriteUtils.TryWriteDirect(CmdStrings.RESP_OK, ref dcurr, dend))