Skip to content

Locking access of entries in auth_server_static#4345

Merged
demmer merged 2 commits intovitessio:masterfrom
planetscale:abhi-atomic
Nov 14, 2018
Merged

Locking access of entries in auth_server_static#4345
demmer merged 2 commits intovitessio:masterfrom
planetscale:abhi-atomic

Conversation

@avaidyanatha
Copy link
Copy Markdown
Contributor

Main Changes

  • loadConfigFromParams is now called in a goroutine
  • Mutex changed to RWMutex

Signed-off-by: avaidyanatha avaidyanatha@ucsb.edu

Signed-off-by: avaidyanatha <avaidyanatha@ucsb.edu>
@avaidyanatha
Copy link
Copy Markdown
Contributor Author

@demmer This should address your concerns with #4294!

@dkhenry dkhenry requested a review from demmer November 7, 2018 00:40
Copy link
Copy Markdown
Member

@demmer demmer left a comment

Choose a reason for hiding this comment

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

Thanks for jumping on this @avaidyanatha -- I have some suggestions that might not have been super clear originally but I hope make sense here.

a.LastAuthRotation = time.Now()
lastAuth := a.LastAuthRotation
if (time.Now().Unix() - lastAuth) > *mysqlAuthRotationTime {
if swapped := atomic.CompareAndSwapInt64(&a.LastAuthRotation, lastAuth, time.Now().Unix()); swapped {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It seems to me the whole thing would be simplified if we just spun up a Timer instance to re-read the config periodically rather than trying to load it on-demand.

That way the regular accessor threads don't have to worry about checking the update time.

It might require adding a simple Stop() interface to the AuthServer so we can stop the timer at shutdown time, but that seems pretty straightforward IMO and would be an improvement.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm thinking we should do a uniform scheme that applies to all files. Currently, some are reloaded through a SIGHUP. So, I'd say let's do the SIGHUP handling for this definitely.

The next question: will a timer based reload be still be useful once we have SIGHUP? Not sure. What do you think?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh that's a good point.

In fact looking at the code, the mysql auth server itself handles SIGHUP already, so maybe this whole effort should be rolled back?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This makes sense, I've rolled back the auth rotation changes and changed the mutex back to a normal one.

Copy link
Copy Markdown
Member

@demmer demmer left a comment

Choose a reason for hiding this comment

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

Overall this is looking much better, but there are a couple of potentially dangerous locking patterns still in the code that I noticed.

We should be really careful to not hold locks while doing external activity like system calls and especially not while waiting for packets from clients.

Signed-off-by: avaidyanatha <avaidyanatha@ucsb.edu>
@avaidyanatha
Copy link
Copy Markdown
Contributor Author

@demmer Worked with Sugu on these changes - should be good now.

@demmer
Copy link
Copy Markdown
Member

demmer commented Nov 14, 2018

Looks great now. Thanks for tidying this up!

@demmer demmer merged commit 3dc3648 into vitessio:master Nov 14, 2018
@avaidyanatha avaidyanatha changed the title Atomic handling of secret rotation Locking access of entries in auth_server_static Nov 14, 2018
@harshit-gangal harshit-gangal deleted the abhi-atomic branch July 17, 2020 16:37
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.

3 participants