[erlang-questions] handling crash on db connect

Jesper Louis Andersen jesper.louis.andersen@REDACTED
Thu Jun 6 11:57:46 CEST 2013



On Jun 5, 2013, at 10:59 PM, Paul Rubin <paul@REDACTED> wrote:

> I'm using gar1t's redis driver and find that if the redis server is running, redis:connect() causes the client to crash.  try/catch doesn't handle it, so I think it's linking some other process which then crashes and propagates the exit.
> 
> What's the right way to handle the crash, in order to report some reasonable error and/or do a sleep/retry loop?  One obvious way is trapexit() and explicitly handle the exit signal, but I have the impression that this would be overly drastic in Erlang.  Connection failure to a db should be a fairly routine error condition, so I feel like there's something I'm missing.
> 
> Any advice?  Thanks.
> 

Rewrite the driver? It makes sense to return some kind of error tuple in this case because it is expected behaviour that you cannot establish a connection. Then you can crash on

  ok = redis:connect(…)

which is better. Of course this is a matter of style, but I much prefer attempts at connections to be able to fail like this.

Jesper Louis Andersen
  Erlang Solutions Ltd., Copenhagen

> Paul
> 
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list