fix(gw-exproto): fix grpc remote call
This commit is contained in:
parent
6e7d3d05e4
commit
ba9ad47cc1
|
@ -22,9 +22,10 @@
|
|||
-include("src/exproto/include/emqx_exproto.hrl").
|
||||
-include_lib("emqx/include/logger.hrl").
|
||||
|
||||
|
||||
-define(IS_QOS(X), (X =:= 0 orelse X =:= 1 orelse X =:= 2)).
|
||||
|
||||
-define(DEFAULT_CALL_TIMEOUT, 5000).
|
||||
|
||||
%% gRPC server callbacks
|
||||
-export([ send/2
|
||||
, close/2
|
||||
|
@ -117,18 +118,22 @@ to_pid(ConnStr) ->
|
|||
binary_to_term(base64:decode(ConnStr)).
|
||||
|
||||
call(ConnStr, Req) ->
|
||||
case catch to_pid(ConnStr) of
|
||||
{'EXIT', {badarg, _}} ->
|
||||
{error, ?RESP_PARAMS_TYPE_ERROR,
|
||||
<<"The conn type error">>};
|
||||
Pid when is_pid(Pid) ->
|
||||
case erlang:is_process_alive(Pid) of
|
||||
true ->
|
||||
emqx_gateway_conn:call(Pid, Req);
|
||||
false ->
|
||||
{error, ?RESP_CONN_PROCESS_NOT_ALIVE,
|
||||
<<"Connection process is not alive">>}
|
||||
end
|
||||
try
|
||||
Pid = to_pid(ConnStr),
|
||||
emqx_gateway_conn:call(Pid, Req, ?DEFAULT_CALL_TIMEOUT)
|
||||
catch
|
||||
exit : badarg ->
|
||||
{error, ?RESP_PARAMS_TYPE_ERROR, <<"The conn type error">>};
|
||||
exit : noproc ->
|
||||
{error, ?RESP_CONN_PROCESS_NOT_ALIVE,
|
||||
<<"Connection process is not alive">>};
|
||||
exit : timeout ->
|
||||
{error, ?RESP_UNKNOWN, <<"Connection is not answered">>};
|
||||
Class : Reason : Stk->
|
||||
?LOG(error, "Call ~p crashed: {~0p, ~0p}, "
|
||||
"stacktrace: ~0p",
|
||||
[Class, Reason, Stk]),
|
||||
{error, ?RESP_UNKNOWN, <<"Unkwown crashs">>}
|
||||
end.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue