TLDR: Does there exist reusable code for automatically reconnecting to a TCP server that sometimes fails?
I'm writing a server application -- call it hal
-- that also opens some TCP connections to other servers -- among them xbmc
. I had originally written it so that when xbmc
failed, the xbmc
erlang process would stop and subsequently be restarted by its supervisor.
Apparently, this is not a good way to do persistent TCP connections in erlang. First of all, it doesn't really work: When xbmc
failed, the processs would restart too quickly, and the supervisor would shut down the entire hal
program. Secondly, I am apparently not supposed to use the supervisor for this: Erlang Supervisor Strategy For Restarting Connections to Downed Hosts (As I read it, this linked question only answers "does supervisor solve this?", and is not a duplicate of my question)
I'm thinking this sounds like a reasonably common use case, keeping a TCP connection as connected as possible even with a host that goes down now and then. Is there some OTP or other library code I should use to achieve this?