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

Handle UV server shutdown and allow socket activation #42

Merged
merged 6 commits into from
Oct 31, 2024

Conversation

tchernobog
Copy link
Contributor

@tchernobog tchernobog commented Oct 30, 2024

This change 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.
  • integration to other event loops, by subclassing 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 of
in the destructor of grpcxx::uv::server::loop_t. Valgrind
does 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.

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.
Copy link
Owner

@uatuko uatuko left a 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.
docs/api.md Outdated Show resolved Hide resolved
@uatuko uatuko changed the title feature: handle UV server shutdown, allow socket activation Handle UV server shutdown and allow socket activation Oct 31, 2024
@uatuko uatuko merged commit f3b2ac6 into uatuko:main Oct 31, 2024
7 checks passed
uatuko added a commit that referenced this pull request Dec 22, 2024
This is essentially building on #42 and #44, which introduced external
event loops, and making the libuv api semantically similar to asio.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants