From ecf0c8d7e23694be34bf2de9c8c3bb23c11715b5 Mon Sep 17 00:00:00 2001 From: William Yang Date: Wed, 29 Jun 2022 18:51:20 +0200 Subject: [PATCH] fix(quic): overload protection follows zone config --- apps/emqx/src/emqx_quic_connection.erl | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/apps/emqx/src/emqx_quic_connection.erl b/apps/emqx/src/emqx_quic_connection.erl index e9a392187..5b3d53467 100644 --- a/apps/emqx/src/emqx_quic_connection.erl +++ b/apps/emqx/src/emqx_quic_connection.erl @@ -39,9 +39,9 @@ init(ConnOpts) when is_map(ConnOpts) -> ConnOpts. -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), - case emqx_olp:is_overloaded() of + case emqx_olp:is_overloaded() andalso is_zone_olp_enabled(Zone) of false -> {ok, Pid} = emqx_connection:start_link(emqx_quic_stream, {self(), Conn}, S), receive @@ -67,3 +67,12 @@ connected(_Conn, S) -> shutdown(Conn, S) -> quicer:async_shutdown_connection(Conn, ?QUIC_CONNECTION_SHUTDOWN_FLAG_NONE, 0), {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.