[erlang-questions] SSL Example does not work

zxq9 zxq9@REDACTED
Sat Feb 20 14:20:45 CET 2016


On 2016年2月20日 土曜日 22:14:15 zxq9 wrote:
> On 2016年2月20日 土曜日 12:59:25 Roger Wenham wrote:
> > Hi Magnus,
> > 
> > I did the ssl:start() as you suggested, and it now appears to work. So 
> > why is that necessary?
> > 
> > The program calls:
> > 
> >     application:start(ssl),
> > 
> > which I presume would cause ssl:start() to be called... Why is that not 
> > enough?
> > 
> > Also, is it ok to put the ssl:start() inside the program, and why wasn't 
> > that done?
> > 
> > Lastly, Vimal Kumar suggested I use application:ensure_all_started(ssl), 
> > would that remove the need for the ssl:start() ?
> > 
> > Sorry for all the questions :-)
> 
> 
> Hi Roger.
> 
> The reason that application:start(ssl) doesn't quite cut it is because
> ssl has, as an Erlang application, a few of its own application
> dependencies that ssl:start/0,1 takes care of.
> 
> https://github.com/erlang/otp/blob/82a835d94be7ee5e98d101a29999fedaf6cd75fe/lib/ssl/src/ssl.erl#L67-L77
> 
> Usually you can get away with ensure_started/1, but not in this case
> it seems.

Sorry, just pointing that out is maybe slightly useless. Some variation of
the following may be able to stand in for application:ensure_started/1

  ensure_ssl_started() ->
      case ssl:start() of
          ok                            -> ok;
          {error,{already_started,ssl}} -> ok;
          Error                         -> Error
      end.

Normally you shouldn't need this, though. If your application has crashed
that far back up the chain (to the point that this would be called on
a restart) you probably want to let the node die because something is super
horribly wrong. Or at least that is my assumption, not knowing anything
about your system.

-Craig



More information about the erlang-questions mailing list