[erlang-questions] gen_retry? Re: handling crash on db connect

David Welton davidnwelton@REDACTED
Fri Jun 7 10:01:45 CEST 2013


> The question of how to handle connection problems can be tricky. I
> typically bake this into a "connection handler" type process that
> indeed traps exit and then figures out what to do -- other simply
> let's the client process exit propagate up to the supervisor. I'll
> typically have a retry logic that waits for a period of time after
> failures, logging attempts, errors, etc.

I've chatted about this a bit with the folks on #erlang, and while it
seems there are some reasons that it's tricky, I wonder if it would be
possible to make a behavior that deals with situations like this,
where the code:

* deals with some resource that might go away.

* should not actually crash.

* should know that it is in a degraded state.

* should have a strategy to attempt to reconnect, like, say,
exponential backoff with a max wait time.

This is particularly relevant to database drivers, which is where I
encountered the problem.  For instance, with a web site, you don't
want the whole thing to just fall over because the database is gone,
you want it to return a nice message to the user apologizing for the
problem, and keep trying to connect.

--
David N. Welton

http://www.welton.it/davidw/

http://www.dedasys.com/



More information about the erlang-questions mailing list