Useful or not, from you.
absinthe Multiple pushes per client for subscriptions that have a `context_id`

Environment

  • Elixir version (elixir -v): 1.11.3 (compiled with Erlang/OTP 23)
  • Absinthe version (mix deps | grep absinthe): 1.6.4

Expected behavior

Publishing to a subscription should result in just a single push per client.

Actual behavior

Using a subscription with a context_id results in the same number of pushes as the number of connected clients, so for example if you have 5 clients connected and you publish to a given subscription, all 5 clients will receive the data 5 times each.

This is not true when there is no context_id

Relevant Schema/Middleware Code

I have created a repository to showcase the problem. https://github.com/mupkoo/absinthe-duplicate-subscriptions

Here is a quick view of schema.ex

defmodule ShowcaseWeb.Schema do
  use Absinthe.Schema

  object :item do
    field :title, :string
  end

  query do
  end

  subscription do
    field :change, :item do
      arg :id, non_null(:id)
      config fn %{id: id}, _ -> {:ok, topic: id, context_id: "global"} end
    end

    field :change_private, :item do
      arg :id, non_null(:id)
      config fn %{id: id}, _ -> {:ok, topic: id} end
    end

    field :change_no_args, :item do
      config fn _, _ -> {:ok, topic: "*", context_id: "global"} end
    end
  end
end

This is the test case that showcases the behaviour. https://github.com/mupkoo/absinthe-duplicate-subscriptions/blob/master/test/showcase_web/schema_test.exs#L5-L38


I have mentioned this problem on the absinthe_phoenix package as well https://github.com/absinthe-graphql/absinthe_phoenix/issues/83#issuecomment-823925521

That's a useful answer
Without any help

We observe the same behavior and even worse: turning context_id: "global" made messages from adjacent topics leak to the users who weren't subscribed.