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

Safest way to disconnect redundantly? #139

Open
travisgriggs opened this issue Sep 22, 2021 · 1 comment
Open

Safest way to disconnect redundantly? #139

travisgriggs opened this issue Sep 22, 2021 · 1 comment

Comments

@travisgriggs
Copy link

travisgriggs commented Sep 22, 2021

A second/redundant call to Tortoise.Connection.disconnect/1 creates all kinds of heartache. I tried to inline the two lines of code that make up this API:

  connection_pid = Tortoise.Connection.via_name(connection_id) |> IO.inspect(label: "CONNECTION_PID")
  GenServer.call(connection_pid, :disconnect) |> IO.inspect(label: ":DISCONNECT call")

What I found is that the registry seems to still know about the connection/pid pairing after the disconnect (maybe it eventually goes away?)

But I can't figure how to safely issue a disconnect. The call blows up. And in a way that I can't even seem to get a rescuing hander around it. I can't even figure out how to put together a query that would determine if the client_id is registered or not.

@travisgriggs
Copy link
Author

travisgriggs commented Sep 22, 2021

I ended up further inlining the via: registry lookup:

  Registry.lookup(Tortoise.Registry, {Tortoise.Connection, connection_id})
    |> case do
      [{pid, nil}] -> GenServer.call(pid, :disconnect)
      _ -> connection_id |> IO.inspect(label: "CONNECTION NOT PRESENT")
    end

This seems kind of roundabout, but it works. I think disconnect() should never fail. So I'll always use this instead of the current disconnect/1 API.

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