-
Notifications
You must be signed in to change notification settings - Fork 62
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
support unix domain sockets as host in grpc_client #64
Conversation
This allows communication with a grpc server that is listening on the HTTP/2-over-UDS scheme. UDS sockets compared with loopback TCP: * UDS needs no loopback IP interface * UDS can use filesystem-based access control * UDS has no TCP/IP stack encapsulation overhead (higher throughput, less CPU use depending on use-case) * For UDS, the HTTP/2 pseudo-header `:authority` needs a workaround, as the hostname is not a string but a tuple, and it may contain nul or slash characters which are not valid to send as values. The grpc-go client implementation sets the `:authority` to the hardcoded string `"localhost"`, so that behavior is followed, see grpc/grpc-go#3730 If the `{local, UnixSockPath}` tuple is passed along from grpcbox to chatterbox, then the functionality is working well, so there is not much impact on grpcbox aside from updating the `:authority` field appropriately. Note: the UDS usage is not documented in `chatterbox`, their spec says that the host must be type `string()` but it causes no issues with their library if that is not the case, as they just pass the value through to `gen_tcp` which supports the unix socket notation.
@@ -9,7 +9,7 @@ | |||
acceptor_pool, | |||
gproc, | |||
ctx]}, | |||
{env, [{client, #{channels => [%% {default_channel, round_robin, [{http, "localhost", 8080, []}], #{}} |
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.
Fixed this example, the round_robin option should have been inside the last argument (#{}
) but it is the default value anyway so just removed it.
Testing the grpcbox clientI used the grpc/examples/python/helloworld:
Result:
|
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #64 +/- ##
==========================================
- Coverage 39.53% 39.48% -0.06%
==========================================
Files 28 28
Lines 2122 2125 +3
==========================================
Hits 839 839
- Misses 1283 1286 +3
☔ View full report in Codecov by Sentry. |
Since the server side does not work with unix sockets (in this PR), not sure how this could be tested in-repo. |
Nice! This was actually on my todo list :) Will review soon. |
On topic of testing difficulties in-repo, I did make an experimental commit for the server-side support too out of curiosity, but it seems quite a bit more complicated than client side because socket listener options are very different compared to TCP/IP. Notably
In any case, for viewing, that experiment is at PleasantMachine9@7c33d16 but I think it would be a separate PR anyhow. |
This allows communication with a grpc server that is listening
on the HTTP/2-over-UDS scheme.
UDS sockets compared with loopback TCP:
(higher throughput, less CPU use depending on use-case)
:authority
needs a workaround,as the hostname is not a string but a tuple, and it may contain
nul or slash characters which are not valid to send as values.
The grpc-go client implementation sets the
:authority
tothe hardcoded string
"localhost"
, so that behavior is followed,see client: set auth header to localhost for unix target grpc/grpc-go#3730 and support unix-abstract schema grpc/grpc-go#4079
If the
{local, UnixSockPath}
tuple is passed alongfrom grpcbox to chatterbox, then the functionality
is working well, so there is not much impact on grpcbox aside
from updating the
:authority
field appropriately.Note: the UDS usage is not documented in
chatterbox
,their spec says that the host must be type
string()
but it causes no issues with their library if that is not the case,
as they just pass the value through to
gen_tcp
which supports the unix socket notation.