elixir-grpc / grpc

An Elixir implementation of gRPC
https://hex.pm/packages/grpc
Apache License 2.0
1.38k stars 212 forks source link

Use newer type Supervisor.child_spec() instead of Supervisor.Spec.spec() for cowboy adapter #265

Closed prihandi closed 2 years ago

prihandi commented 2 years ago

I've just tried to run GRPC server as a plugin in VerneMQ. Then I found an error pointing to

https://github.com/elixir-grpc/grpc/blob/c7ee0c11ad9eb95a8925a342af8e2d5b1f082fee/lib/grpc/server/adapters/cowboy.ex#L45-L46

turns out current VerneMQ using newer ranch version (2.1.0) instead of old (1.8.0), and the pattern match failed because newer versin of ranch using new map version of :supervisor.child_spec instead of the old 5/6 elements tuple.

Then I seek Phoenix/Plug implementation, because phoenix runs well on my plugin. I found they're using below approach that returning map version instead of the tuple version

https://github.com/elixir-plug/plug_cowboy/blob/d5b54031fb7fe98b8f2025e51587db988e4dabf0/lib/plug/cowboy.ex#L257-L270

    case :ranch.child_spec(ref, ranch_module, transport_opts, cowboy_protocol, proto_opts) do
      {id, start, restart, shutdown, type, modules} ->
        %{
          id: id,
          start: start,
          restart: restart,
          shutdown: shutdown,
          type: type,
          modules: modules
        }

      child_spec when is_map(child_spec) ->
        child_spec
    end

I think it's better for this lib do similar approach, for the sake of compatibility

polvalente commented 2 years ago

PRs are welcome!