Skip to content
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

SSE: Getting "closed" instead of :closed when client disconnects #294

Open
fladens opened this issue Sep 11, 2024 · 0 comments
Open

SSE: Getting "closed" instead of :closed when client disconnects #294

fladens opened this issue Sep 11, 2024 · 0 comments

Comments

@fladens
Copy link

fladens commented Sep 11, 2024

Hello everyone 👋 Thanks for this great package!

I am using

  • absinthe_plug (1.5.8)
  • Phoenix (1.7.14)
  • Bandit (1.5.5).

I use Server-Sent-Events for graphql subscriptions and I am running into the following issue when the client disconnects, for example through closing of a tab or reloading.

[error] ** (CaseClauseError) no case clause matching: {:error, "closed"}
    (absinthe_plug 1.5.8) lib/absinthe/plug.ex:385: Absinthe.Plug.subscribe_loop/3

for the lines here:

receive do
%{event: "subscription:data", payload: %{result: result}} ->
case chunk(conn, "#{encode_json!(result, config)}\n\n") do
{:ok, conn} ->
subscribe_loop(conn, topic, config)
{:error, :closed} ->
Absinthe.Subscription.unsubscribe(config.context.pubsub, topic)
conn
end
:close ->
Absinthe.Subscription.unsubscribe(config.context.pubsub, topic)
conn
after
30_000 ->
case chunk(conn, ":ping\n\n") do
{:ok, conn} ->
subscribe_loop(conn, topic, config)
{:error, :closed} ->
Absinthe.Subscription.unsubscribe(config.context.pubsub, topic)
conn
end
end

It seems to me I would just need to add {:error, "closed"}, however, since it feels a bit redundant and I am quite new to elixir wanted to make sure this is what is indeed needed.

I can create a PR for it though.


It might be a difference in how Bandit and Cowboy are handling errors, not sure if I can possibly overwrite this to actually return atoms instead, couldn't find anything though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant