Skip to content

GRPC.Client.Connection.init/1 not being cleaned up #27

@fadhil-sc

Description

@fadhil-sc

We're using ConnGRPC to create a pool of GRPC connections.

defmodule SomeApi do
  use ConnGRPC.Pool,
    pool_size: 2,
    channel: [
      address: "https://grpc_server.cloud:443",
      opts: []
    ]

This works, and we see the pool being used to get channels correctly. However, when the pools are restarted (like after a network failure), we see an increasing number of GRPC.Client.Connection.init/1 processes, corresponding to the number of pools x pool size.

We tried running a Process.exit on all of the GRPC.Client.Connection process in the on_disconnect callback, but that doesn't seem to work. It seems like the on_connect and on_disconnect function being passed in the arguments are being overridden in:

  defp build_channels_supervisor_spec(pool_name, pool_size, channel_opts, registry_name) do
    channel_opts =
      channel_opts
      |> Keyword.put(:on_connect, fn -> Registry.register(registry_name, :channels, nil) end)
      |> Keyword.put(:on_disconnect, fn -> Registry.unregister(registry_name, :channels) end)
      |> Keyword.put(:pool_name, pool_name)

    channels_specs =
      for index <- 1..pool_size//1 do
        Supervisor.child_spec({ConnGRPC.Channel, channel_opts}, id: {ConnGRPC.Channel, index})
      end

    %{
      id: :channels_supervisor,
      type: :supervisor,
      start: {Supervisor, :start_link, [channels_specs, [strategy: :one_for_one]]}
    }
  end

Our on_disconnect (and on_connect) work if we comment out the first two Keyword.put (lines 247 & 248). Would this be the right fix for it?

Here's an example of how we're using the pools:

case @pool_tokens.get_channel() do
      {:ok, channel} ->
        get_token_with_channel(channel, access_info)

      {:error, reason} ->

        {:error, reason}
 end

  defp get_token_with_channel(channel, access_info) do
     ...
        TokenService.Stub.exchange(channel, access_token_request)

      error ->
        error
    end
  end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions