-
Notifications
You must be signed in to change notification settings - Fork 11
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
Handle UV server shutdown and allow socket activation #42
Conversation
This commit adds: - socket activation support, to allow the caller to pass a pre-existing bound tcp socket to server::run(). This is important in contexts where it is necessary to set some particular flags on the socket (such as keepalive), or if the socket is already created at program start (as is the case with the systemd socket activation protocol). - server shutdown support, to allow signaling the server via a std::stop_token that it should clean up and cleanly exit. Two unit tests were added. Running valgrind on the resulting binary also revealed a leak due to failure to cleanup a the uv_handle_t with the connection, this is now taken care of in the destructor of grpcxx::uv::server::loop_t. Valgrind does not report any more leaks during test execution.
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 as always 👏 and thanks for the PR!
There are a few things I'd tidy up with how I'd add tests but that's just personal preference and can be changed later (or not). I intentionally used g++ in macOS builds in the GitHub workflow since I normally use clang with macOS, I can check if I could figure out the issue with g++ when this is merged.
One request, I see you've added code comments which is great but could you update the API docs as well please?
This change adds the ability to subclass grpcxx::uv::server to be able to trigger individual loop iterations. This makes it possible to run the server as a nested loop inside either libuv, or optionally via a different framework (like libevent). Additionally, the following two bugs were fixed: - also support binding to IPv6 addresses - fix generation of source files from proto files when no package is specified. Note that, due to the current lack of a client-side gRPC implementation, the tests are not checking the full flow. Therefore, my approach was to add a sleep in the code and use Postman to check the service used in the tests answers correctly.
This change adds:
pre-existing bound tcp socket to server::run(). This
is important in contexts where it is necessary to set
some particular flags on the socket (such as keepalive),
or if the socket is already created at program start
(as is the case with the systemd socket activation protocol).
via a
std::stop_token
that it should clean up and cleanly exit.uv::server
and allowing iterating through the loop just once.
Three unit tests were added. Running valgrind on the resulting
binary also revealed a leak due to failure to cleanup a
the
uv_handle_t
with the connection, this is now taken care ofin the destructor of
grpcxx::uv::server::loop_t
. Valgrinddoes not report any more leaks during test execution.
Additionally, a bug in the generation of sources from proto
files when no package name is present was fixed.