Skip to content

Maybe this is a bug? #192

@wwhai

Description

@wwhai

Today I ready to add a UDP listener in emqx,When I add it to esockd , it work normal but detected an error in "managerment listener". My code in here:
This code used to support raw udp:

start_urap_listener()->
    Opts = [{udp_options, [binary, {reuseaddr, true}]}],
    MFA = {emqx_urap_connection, start_link, []},
    esockd:open_udp('urap:udp', 1885, Opts, MFA).

This callback:

%%%-------------------------------------------------------------------
%%% @author admin
%%% @copyright (C) 2020, <COMPANY>
%%% @doc
%%%
%%% @end
%%% Created : 8. 4月 2020 11:20
%%%-------------------------------------------------------------------
-module(emqx_urap_connection).
-author("wwhai").

-behaviour(gen_server).

%% API
-export([start_link/2, init/2]).

%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2,
  code_change/3]).

-define(SERVER, ?MODULE).
-define(UDP_OPTS, [binary, {reuseaddr, true}]).

-record(emqx_urap_state, {}).

%%%===================================================================
%%% API
% %%%===================================================================
% start(Port) ->
%   Opts = [{udp_options, [binary, {reuseaddr, true}]}],
%   MFA = {?MODULE, start_link, []},
%   esockd:open_udp('urap:udp', Port, Opts, MFA).


start_link(Transport, Peer) ->
  {ok, proc_lib:spawn_link(?MODULE, init, [Transport, Peer])}.

init(_T, _P) ->
  gen_server:enter_loop(?MODULE, [], #emqx_urap_state{}).

init(_) -> ok.

%%
%% 消息接收处理
%%

handle_call(_Request, _From, State) ->
  {reply, ok, State}.

handle_info(Msg, State) ->
  io:format("MSG:~p~n", [Msg]),
  {noreply, State}.

terminate(_Reason, _State) ->
  ok.

code_change(_OldVsn, State, _Extra) ->
  {ok, State}.


handle_cast(_Msg, State) ->
  {noreply, State}.

It can work:

  • Client send:
    image
  • Server received:
    image

But front appear this:
image
And error log:

2020-04-08 21:14:46.394 [error] [esockd_udp]: Unexpected call: which_children
2020-04-08 21:14:46.394 [error] GET /api/v4/nodes/emqx@127.0.0.1/listeners error: function_clause, stacktrace:
[{esockd_listener_sup,'-child_pid/2-lc$^0/1-0-',
                      [ignore],
                      [{file,"/mnt/d/github/emqx-rel/_checkouts/esockd/src/esockd_listener_sup.erl"},
                       {line,87}]},
 {esockd_listener_sup,child_pid,2,
                      [{file,"/mnt/d/github/emqx-rel/_checkouts/esockd/src/esockd_listener_sup.erl"},
                       {line,87}]},
 {esockd,get_acceptors,1,
         [{file,"/mnt/d/github/emqx-rel/_checkouts/esockd/src/esockd.erl"},
          {line,194}]},
 {emqx_mgmt,'-list_listeners/1-fun-0-',1,
            [{file,"/mnt/d/github/emqx-rel/_checkouts/emqx_management/src/emqx_mgmt.erl"},
             {line,391}]},
 {lists,map,2,[{file,"lists.erl"},{line,1239}]},
 {lists,map,2,[{file,"lists.erl"},{line,1239}]},
 {emqx_mgmt,list_listeners,1,
            [{file,"/mnt/d/github/emqx-rel/_checkouts/emqx_management/src/emqx_mgmt.erl"},
             {line,388}]},
 {emqx_mgmt_api_listeners,list,2,
                          [{file,"/mnt/d/github/emqx-rel/_checkouts/emqx_management/src/emqx_mgmt_api_listeners.erl"},
                           {line,37}]}]

I checked code fond in here:
image

It looks like current version only filter tcpkeywords but no udp?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions