-
Notifications
You must be signed in to change notification settings - Fork 9.9k
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
server/embed: fix data race when start insecure grpc #15509
Conversation
There are two goroutines accessing the `gs` grpc server var. Before insecure `gs` server start, the `gs` can be changed to secure server and then the client will fail to connect to etcd with insecure request. It is data-race. We should use argument for reference in the new goroutine. fix: etcd-io#15495 Signed-off-by: Wei Fu <fuweid89@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! Thank you @fuweid
defer func(gs *grpc.Server) { | ||
if err != nil { | ||
sctx.lg.Warn("stopping secure grpc server due to error", zap.Error(err)) | ||
gs.Stop() | ||
sctx.lg.Warn("stopped secure grpc server due to error", zap.Error(err)) | ||
} | ||
}(gs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comment: the code block is almost identical to the code block for insecure. I am thinking to define a separate function something like below, then call it in both secure and insecure code block.
func closegRPCServer(gs *grpc.Server) {
...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it needs return error
to the log, I'm not sure how to handle this with your idea. In here, I follow the defer pattern~
@fuweid Could you backport it to release-3.5 and release-3.4? |
Sure! Will send prs later. |
Add item **server/embed: fix data race when start insecure grpc** to 3.4/3.5 changelog. REF: etcd-io#15509 Signed-off-by: Wei Fu <fuweid89@gmail.com>
Add item [server/embed: fix data race when starting both secure & insecure gRPC servers on the same address] to 3.4/3.5 changelog. REF: etcd-io#15509 Signed-off-by: Wei Fu <fuweid89@gmail.com>
There are two goroutines accessing the
gs
grpc server var. Before insecuregs
server start, thegs
can be changed to secure server and then the client will fail to connect to etcd with insecure request. It is data-race. We should use argument for reference in the new goroutine.fix: #15495
Please read https://github.com/etcd-io/etcd/blob/main/CONTRIBUTING.md#contribution-flow.