tpitale
Reconnecting to a remote node
Background
I’ve got two nodes, one is the “notifier” the other is the “consumer”. The consumer subscribes to (using GenStage) the notifier. When they lose connection I get a message DOWN with :noconnection. I’m currently letting the consumer crash and restart using my supervisor. This works except for the error logs it generates.
Question
How do I capture that message, wait for a short time, and then re-establish the connection to the remote node?
Currently, thinking something like this:
def handle_info({:DOWN, _ref, :process, _info, :noconnection}, state) do
Process.sleep(500)
{:stop, :restart, state}
end
But I think the non-normal stop will still log an error before restarting.
If I use :noreply instead the supervisor won’t restart the consumer. Will the connection be re-established by GenStage (or something underneath) once it is reachable again? The answer appears to be yes based on this post: Autoreconnect nodes - #2 by tty
But, it’s still unclear to me if it’s safe (or a terrible idea) to just eternally swallow the DOWN message.
How would you handle this scenario?
First Post!
tpitale
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #javascript
- #code-sync
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









