-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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 a multithreading bug in grpc ClientCall
#5196
Conversation
GrpcServer(const std::string &name, const uint32_t port) | ||
: name_(name), port_(port), is_closed_(true) {} | ||
GrpcServer(std::string name, const uint32_t port) | ||
: name_(std::move(name)), port_(port), is_closed_(true) {} |
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.
The previous code seemed clearer to me, why did you change it?
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.
Clang-tidy suggests this change. Passing by value + move has some advantages over passing by const reference + copy.
The biggest advantage is that you can avoid copying data. E.g.,
std::string name = "....";
GrpcServer(std::move(name)); // no copy at all.
See https://stackoverflow.com/questions/51705967/advantages-of-pass-by-value-and-stdmove-over-pass-by-reference/51706522 for more details.
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.
Ok interesting, thanks for the explanation :)
Test PASSed. |
Test FAILed. |
What do these changes do?
Problem.
ClientCallManager
returns a raw pointer ofClientCall
, and the caller can usecall->GetStatus()
to tell whether the request was successfully sent. However, there's a small chance that the reply is received too fast. And a call may be deleted beforecall->GetStatus()
.Solution
This PR fixes this issue by adding a
ClientCallTag
and makeClientCall
ashared_ptr
.Also fixes some typos and some small issues reported by clang-tidy.
Related issue number
Linter
scripts/format.sh
to lint the changes in this PR.