Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions grpc_server/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

* A server stream no longer hangs when two calls on one connection fill Cowboy's send buffers. If a stream waited for its stream buffer to drain and the connection buffer then filled, the second alarm made the stream forget it was waiting. When the buffers drained it got no ack, and the call never ended, however fast the client read (#652).

* `GRPC.Server.Supervisor` crashed on unix sockets (`adapter_opts: [ip: {:local, path}]`). This is now fixed (#665).

## v1.1.0 - 2026-11-13

### Enhancements
Expand Down
18 changes: 6 additions & 12 deletions grpc_server/lib/grpc/server/adapters/cowboy.ex
Original file line number Diff line number Diff line change
Expand Up @@ -405,20 +405,14 @@ defmodule GRPC.Server.Adapters.Cowboy do
defp contains?(_, _), do: false

defp running_info(scheme, endpoint, servers, ref) do
{addr, port} = :ranch.get_addr(ref)

addr_str =
case addr do
:undefined ->
raise "undefined address for ranch server"

addr ->
"#{:inet.ntoa(addr)}:#{port}"
end

"Running #{servers_name(endpoint, servers)} with Cowboy using #{scheme}://#{addr_str}"
"Running #{servers_name(endpoint, servers)} with Cowboy using " <>
listen_address(scheme, :ranch.get_addr(ref))
end

defp listen_address(scheme, {:local, path}), do: "#{scheme} on unix:#{path}"
defp listen_address(_scheme, {:undefined, _}), do: raise("undefined address for ranch server")
defp listen_address(scheme, {ip, port}), do: "#{scheme}://#{:inet.ntoa(ip)}:#{port}"

# Without an endpoint, `Module.concat(nil, Dispatch)` is one key for all listeners.
# Each listener needs its own routes, so the key uses the listener name.
defp dispatch_key(nil, servers), do: {__MODULE__, :dispatch, servers_name(nil, servers)}
Expand Down
51 changes: 51 additions & 0 deletions grpc_server/test/grpc/server/adapters/cowboy_unix_socket_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
defmodule GRPC.Server.Adapters.CowboyUnixSocketTest do
use ExUnit.Case, async: true

import ExUnit.CaptureLog

defmodule Greeter do
use GRPC.Server, service: Helloworld.Greeter.Service

def say_hello(%{name: name}, _stream), do: %Helloworld.HelloReply{message: "Hello #{name}"}
end

@reply_timeout_ms 5_000

setup do
path = Path.join(System.tmp_dir!(), "grpc_#{System.unique_integer([:positive])}.sock")
on_exit(fn -> File.rm(path) end)
%{path: path}
end

test "the supervisor serves on a unix socket and logs its path", %{path: path} do
log =
capture_log(fn ->
start_supervised!(
{GRPC.Server.Supervisor,
servers: [Greeter], port: 0, start_server: true, adapter_opts: [ip: {:local, path}]}
)
end)

assert log =~ "Running #{inspect(Greeter)} with Cowboy using http on unix:#{path}"
assert say_hello(path, "unix") == %Helloworld.HelloReply{message: "Hello unix"}
end

defp say_hello(path, name) do
{:ok, conn} = :gun.open_unix(String.to_charlist(path), %{protocols: [:http2]})
on_exit(fn -> :gun.close(conn) end)
{:ok, :http2} = :gun.await_up(conn, @reply_timeout_ms)

message = Protobuf.encode(%Helloworld.HelloRequest{name: name})
headers = [{"content-type", "application/grpc"}, {"te", "trailers"}]
body = <<0, byte_size(message)::32, message::binary>>
ref = :gun.post(conn, "/helloworld.Greeter/SayHello", headers, body)

{:response, :nofin, 200, _headers} = :gun.await(conn, ref, @reply_timeout_ms)

{:ok, <<0, size::32, reply::binary-size(size)>>, trailers} =
:gun.await_body(conn, ref, @reply_timeout_ms)

assert {"grpc-status", "0"} in trailers
Protobuf.decode(reply, Helloworld.HelloReply)
end
end
Loading