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("src/exproto/include/emqx_exproto.hrl").
|
||||||
-include_lib("emqx/include/logger.hrl").
|
-include_lib("emqx/include/logger.hrl").
|
||||||
|
|
||||||
|
|
||||||
-define(IS_QOS(X), (X =:= 0 orelse X =:= 1 orelse X =:= 2)).
|
-define(IS_QOS(X), (X =:= 0 orelse X =:= 1 orelse X =:= 2)).
|
||||||
|
|
||||||
|
-define(DEFAULT_CALL_TIMEOUT, 5000).
|
||||||
|
|
||||||
%% gRPC server callbacks
|
%% gRPC server callbacks
|
||||||
-export([ send/2
|
-export([ send/2
|
||||||
, close/2
|
, close/2
|
||||||
|
@ -117,18 +118,22 @@ to_pid(ConnStr) ->
|
||||||
binary_to_term(base64:decode(ConnStr)).
|
binary_to_term(base64:decode(ConnStr)).
|
||||||
|
|
||||||
call(ConnStr, Req) ->
|
call(ConnStr, Req) ->
|
||||||
case catch to_pid(ConnStr) of
|
try
|
||||||
{'EXIT', {badarg, _}} ->
|
Pid = to_pid(ConnStr),
|
||||||
{error, ?RESP_PARAMS_TYPE_ERROR,
|
emqx_gateway_conn:call(Pid, Req, ?DEFAULT_CALL_TIMEOUT)
|
||||||
<<"The conn type error">>};
|
catch
|
||||||
Pid when is_pid(Pid) ->
|
exit : badarg ->
|
||||||
case erlang:is_process_alive(Pid) of
|
{error, ?RESP_PARAMS_TYPE_ERROR, <<"The conn type error">>};
|
||||||
true ->
|
exit : noproc ->
|
||||||
emqx_gateway_conn:call(Pid, Req);
|
|
||||||
false ->
|
|
||||||
{error, ?RESP_CONN_PROCESS_NOT_ALIVE,
|
{error, ?RESP_CONN_PROCESS_NOT_ALIVE,
|
||||||
<<"Connection process is not alive">>}
|
<<"Connection process is not alive">>};
|
||||||
end
|
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.
|
end.
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue