From 24c8ad943a02132944677423e0c5d455d279620e Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Mon, 31 Aug 2015 17:44:24 +0200 Subject: Handle hsmhelper port crashes by restarting the signing gen_server. Match on exit_status messages and return stop. Timeout on receive and return stop. --- src/sign.erl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/sign.erl b/src/sign.erl index 07c5047..5949ad1 100644 --- a/src/sign.erl +++ b/src/sign.erl @@ -51,6 +51,7 @@ init([]) -> Port = open_port({spawn_executable, code:priv_dir(plop) ++ "/hsmhelper"}, [{args, Args}, + exit_status, {packet, 4}]), {ok, #state{pubkey = Public_key, hsmport = Port, @@ -234,6 +235,14 @@ handle_call({sign, Data}, _From, State) -> {Port, {data, RawSignature}} when is_port(Port) -> Signature = encode_ec_signature(list_to_binary(RawSignature), 256), lager:debug("received signing reply from HSM: ~p", [Signature]), - {reply, Signature, State} + {reply, Signature, State}; + {Port, {exit_status, ExitStatus}} -> + lager:error("hsmhelper port ~p exiting with status ~p", + [Port, ExitStatus]), + {stop, portexit, State} + after + 10000 -> + lager:error("HSM timeout"), + {stop, timeout, State} end end. -- cgit v1.1