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

xds/client: hold authority mutex before making a new authority #5331

Merged
merged 2 commits into from May 3, 2022

Conversation

menghanl
Copy link
Contributor

fixes #5328

Caller must hold the mutex before calling newAuthority.

RELEASE NOTES:

  • xds/client: fix a potential concurrent map read/write in load reporting

@@ -28,7 +28,9 @@ import (
// It returns a Store for the user to report loads, a function to cancel the
// load reporting stream.
func (c *clientImpl) ReportLoad(server *bootstrap.ServerConfig) (*load.Store, func()) {
c.authorityMu.Lock()
a, err := c.newAuthority(server)
Copy link
Member

Choose a reason for hiding this comment

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

Should we name the function newAuthorityLocked to better indicate you should have the lock when calling it? I see it's in the doc comments but those obviously weren't sufficient in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Rename this and several other methods.

@dfawley dfawley assigned menghanl and unassigned dfawley Apr 29, 2022
@@ -38,6 +40,6 @@ func (c *clientImpl) ReportLoad(server *bootstrap.ServerConfig) (*load.Store, fu
store, cancelF := a.reportLoad()
return store, func() {
cancelF()
c.unrefAuthority(a)
c.unrefAuthorityLocked(a)
Copy link
Member

Choose a reason for hiding this comment

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

Is this cleanup function always invoked with the lock held?

@@ -28,7 +28,7 @@ import (
// after the watcher is canceled. The caller needs to handle this case.
func (c *clientImpl) WatchListener(serviceName string, cb func(xdsresource.ListenerUpdate, error)) (cancel func()) {
n := xdsresource.ParseName(serviceName)
a, unref, err := c.findAuthority(n)
a, unref, err := c.findAuthorityLocked(n)
Copy link
Member

Choose a reason for hiding this comment

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

Lock isn't held? And below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ohh, the other two actually says must not hold mu.....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Member

Choose a reason for hiding this comment

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

Geez, who wrote this code? 😉

@menghanl menghanl merged commit 78b13f2 into grpc:master May 3, 2022
@menghanl menghanl deleted the xds_client_lock branch May 3, 2022 20:39
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 31, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

xds: concurrent map read and map write
2 participants