Skip to content

Commit bcfb113

Browse files
committed
Fix the rate limit bug
1 parent 51fa7e0 commit bcfb113

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/esockd_udp.erl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ stop(Pid) -> gen_server:stop(Pid).
8383

8484
init([Proto, Port, Opts, MFA]) ->
8585
process_flag(trap_exit, true),
86+
put(incoming_peers, 0),
8687
{UdpOpts, State} = parse_opt(Opts, [], #state{proto = Proto,
8788
port = Port,
8889
max_peers = infinity,
@@ -124,6 +125,7 @@ handle_info({udp, Sock, IP, InPortNo, Packet}, State = #state{sock = Sock, peers
124125
Pid ! {datagram, self(), Packet},
125126
{noreply, State};
126127
error ->
128+
put(incoming_peers, get(incoming_peers) + 1),
127129
try should_throttle(State) orelse
128130
start_channel({udp, self(), Sock}, Peer, State) of
129131
true ->
@@ -147,7 +149,8 @@ handle_info({udp, Sock, IP, InPortNo, Packet}, State = #state{sock = Sock, peers
147149
end;
148150

149151
handle_info({udp_passive, Sock}, State = #state{sock = Sock, rate_limit = Rl}) ->
150-
NState = case ?ENABLED(Rl) andalso esockd_rate_limit:check(Rl) of
152+
NState = case ?ENABLED(Rl) andalso
153+
esockd_rate_limit:check(put(incoming_peers, 0), Rl) of
151154
false ->
152155
activate_sock(State);
153156
{0, Rl1} ->

0 commit comments

Comments
 (0)