Merge pull request #8365 from qzhuyan/dev/william/bump-quicer

fix(quic): overload protection follows zone config
This commit is contained in:
William Yang 2022-07-01 09:17:22 +02:00 committed by GitHub
commit ff9ed0eab9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 2 deletions

View File

@ -39,9 +39,9 @@ init(ConnOpts) when is_map(ConnOpts) ->
ConnOpts. ConnOpts.
-spec new_conn(quicer:connection_handler(), cb_state()) -> {ok, cb_state()} | {error, any()}. -spec new_conn(quicer:connection_handler(), cb_state()) -> {ok, cb_state()} | {error, any()}.
new_conn(Conn, S) -> new_conn(Conn, #{zone := Zone} = S) ->
process_flag(trap_exit, true), process_flag(trap_exit, true),
case emqx_olp:is_overloaded() of case emqx_olp:is_overloaded() andalso is_zone_olp_enabled(Zone) of
false -> false ->
{ok, Pid} = emqx_connection:start_link(emqx_quic_stream, {self(), Conn}, S), {ok, Pid} = emqx_connection:start_link(emqx_quic_stream, {self(), Conn}, S),
receive receive
@ -67,3 +67,12 @@ connected(_Conn, S) ->
shutdown(Conn, S) -> shutdown(Conn, S) ->
quicer:async_shutdown_connection(Conn, ?QUIC_CONNECTION_SHUTDOWN_FLAG_NONE, 0), quicer:async_shutdown_connection(Conn, ?QUIC_CONNECTION_SHUTDOWN_FLAG_NONE, 0),
{ok, S}. {ok, S}.
-spec is_zone_olp_enabled(emqx_types:zone()) -> boolean().
is_zone_olp_enabled(Zone) ->
case emqx_config:get_zone_conf(Zone, [overload_protection]) of
#{enable := true} ->
true;
_ ->
false
end.