chore(psk): catch timeout exception to avoid crash

This commit is contained in:
zhouzb 2021-09-26 20:37:00 +08:00
parent 98ecafcceb
commit f325d7c783
1 changed files with 9 additions and 1 deletions

View File

@ -91,7 +91,7 @@ on_psk_lookup(PSKIdentity, _UserState) ->
end. end.
import(SrcFile) -> import(SrcFile) ->
gen_server:call(?MODULE, {import, SrcFile}). call({import, SrcFile}).
-spec start_link() -> {ok, pid()} | ignore | {error, term()}. -spec start_link() -> {ok, pid()} | ignore | {error, term()}.
start_link() -> start_link() ->
@ -220,3 +220,11 @@ trans(Fun, Args) ->
{atomic, Res} -> Res; {atomic, Res} -> Res;
{aborted, Reason} -> {error, Reason} {aborted, Reason} -> {error, Reason}
end. end.
call(Request) ->
try
gen_server:call(?MODULE, Request, 10000)
catch
exit:{timeout, _Details} ->
{error, timeout}
end.