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

client: call .Endpoints() in dial() in client/v3/client.go instead of accessing cfg.Endpoints directly #13203

Merged
merged 1 commit into from
Jul 29, 2021

Conversation

yishuT
Copy link
Contributor

@yishuT yishuT commented Jul 9, 2021

initialEndpoints := strings.Join(c.cfg.Endpoints, ";")
accesses
endpoints without acquiring lock. Fix it to call Endpoints()

Fix #13201

@serathius
Copy link
Member

I agree that this variable needs a lock to prevent data race with SetEndpoints, but I would also not expect that SetEndpoints should modify Config.
I would not expect config structs like client.v3.Config to be ever mutated by consumers. I expect that SetEndpoints was added later. Mutex withing Client doesn't directly specify which variables are protected by it.

Instead of of just adding lock, maybe we should consider adding dedicated endpoint field to Client struct and specifying explicitly that is protected by mutex?

@yishuT
Copy link
Contributor Author

yishuT commented Jul 9, 2021

yeah, I agree. I only fixed what our race detector complained but didn't read the code in detail. There is one thing that if SetEndpoints is called for a new list of endpoints after client is init, now this client has two different list of endpoints, one in client.cfg, the other in client.endpoint.

@yishuT
Copy link
Contributor Author

yishuT commented Jul 9, 2021

nvm, we don't do deep copy in SetEndpoints

Copy link
Member

@serathius serathius left a comment

Choose a reason for hiding this comment

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

LG

@yishuT
Copy link
Contributor Author

yishuT commented Jul 18, 2021

any updates, or should I do something?

Copy link
Member

@spzala spzala left a comment

Choose a reason for hiding this comment

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

lgtm. Can you please squash commits into one? Thanks @yishuT

@yishuT
Copy link
Contributor Author

yishuT commented Jul 27, 2021

squash commits

@spzala
Copy link
Member

spzala commented Jul 29, 2021

squash commits

Thanks!
CI is good, also tested locally.

@spzala spzala merged commit 4cbb949 into etcd-io:main Jul 29, 2021
@yishuT yishuT deleted the client-race branch July 29, 2021 09:06
chaochn47 added a commit to chaochn47/etcd that referenced this pull request Oct 26, 2023
…lient/v3/client.go instead of accessing cfg.Endpoints directly

Signed-off-by: Chao Chen <chaochn@amazon.com>
chaochn47 added a commit to chaochn47/etcd that referenced this pull request Oct 27, 2023
…lient/v3/client.go instead of accessing cfg.Endpoints directly

Signed-off-by: Chao Chen <chaochn@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

accessing cfg.Endpoints in dial() in client/v3/client.go has race with SetEndpoints
3 participants