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

fix(AclFamily): stream acl updates via dispatch queue in connection #1786

Merged
merged 4 commits into from
Sep 1, 2023

Conversation

kostasrim
Copy link
Contributor

@kostasrim kostasrim commented Sep 1, 2023

There was a bug on updates of the acl categories when squashing was used. Basically, the parent context could be accessed in parallel by the "stub" contexts causing a dreaded data race on the update.

This is fixed by adding a new AclUpdateMessage at the front of the dispatch queue of the connection.

@kostasrim kostasrim requested a review from dranikpg September 1, 2023 11:57
@kostasrim kostasrim self-assigned this Sep 1, 2023
Copy link
Contributor

@dranikpg dranikpg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really wish for a test. For example, make a long running script that jumps on many shards. This means that the control fiber will suspend at some time and StreamUpdatesToAllProactor will have a change to run. Then we make sure that the acl_categories didn't change while the script was running.

Comment on lines +214 to +216
if (ctx && msg.username == ctx->authed_username) {
ctx->acl_categories = msg.categories;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I first thought that you can send this message to a connection only if it already has this specific user. However if a acl setuser operation manages to execute before it it whould've been a bug. So its correct this way

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically the set acluser must complete, since it holds a write lock over the registry.

Comment on lines +82 to +85
struct AclUpdateMessage {
std::string_view username;
uint64_t categories{0};
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment above why we have it at all

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And quick check: are you sure the string_view keeps valid forever? The connection might be very busy and process this message only after a long delay

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I am sure, because we hold a ReadLock on the registry so nobody can actually modify it:

180     auto& registry = ServerState::tlocal()->user_registry;                                           
181     auto user_with_lock = registry->MaybeAddAndUpdateWithLock(username, std::move(req));             
182     if (user_with_lock.exists) {                                                                     
183       StreamUpdatesToAllProactorConnections(username, user_with_lock.user.AclCategory());            
184     }  

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which is a bug! I will fix it, we need a unique_lock!

@kostasrim kostasrim requested a review from dranikpg September 1, 2023 15:21
dranikpg
dranikpg previously approved these changes Sep 1, 2023
@pytest.mark.asyncio
async def test_acl_with_long_running_script(df_server):
client = aioredis.Redis(port=df_server.port)
await client.execute_command("ACL SETUSER roman ON >yoman +@string +@scripting")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yo man wassup 🤣

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shooooorty yoooo

@kostasrim kostasrim enabled auto-merge (squash) September 1, 2023 15:28
@kostasrim kostasrim merged commit 9ca7dba into main Sep 1, 2023
@kostasrim kostasrim deleted the fix_acl_setuser branch September 1, 2023 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants