Merge pull request #11106 from thalesmg/fix-validate-worker-pool-size-master

fix(resource): validate maximum worker pool size
This commit is contained in:
Thales Macedo Garitezi 2023-06-20 16:25:51 -03:00 committed by GitHub
commit 010c2fb0c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 1 deletions

View File

@ -88,7 +88,7 @@ resource_opts_meta() ->
desc => ?DESC(<<"resource_opts">>)
}.
worker_pool_size(type) -> non_neg_integer();
worker_pool_size(type) -> range(1, 1024);
worker_pool_size(desc) -> ?DESC("worker_pool_size");
worker_pool_size(default) -> ?WORKER_POOL_SIZE;
worker_pool_size(required) -> false;

View File

@ -74,6 +74,44 @@ health_check_interval_validator_test_() ->
)
].
worker_pool_size_test_() ->
BaseConf = parse(webhook_bridge_health_check_hocon(<<"15s">>)),
Check = fun(WorkerPoolSize) ->
Conf = emqx_utils_maps:deep_put(
[
<<"bridges">>,
<<"webhook">>,
<<"simple">>,
<<"resource_opts">>,
<<"worker_pool_size">>
],
BaseConf,
WorkerPoolSize
),
#{<<"bridges">> := #{<<"webhook">> := #{<<"simple">> := CheckedConf}}} = check(Conf),
#{<<"resource_opts">> := #{<<"worker_pool_size">> := WPS}} = CheckedConf,
WPS
end,
AssertThrow = fun(WorkerPoolSize) ->
?assertThrow(
{_, [
#{
kind := validation_error,
reason := #{expected_type := _},
value := WorkerPoolSize
}
]},
Check(WorkerPoolSize)
)
end,
[
?_assertEqual(1, Check(1)),
?_assertEqual(100, Check(100)),
?_assertEqual(1024, Check(1024)),
?_test(AssertThrow(0)),
?_test(AssertThrow(1025))
].
%%===========================================================================
%% Helper functions
%%===========================================================================

View File

@ -0,0 +1,3 @@
Added a validation for the maximum number of pool workers of a bridge.
Now the maximum amount is 1024 to avoid large memory consumption from an unreasonable number of workers.