Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(resource): validate maximum worker pool size #11106

Merged
merged 1 commit into from Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/emqx_resource/src/schema/emqx_resource_schema.erl
Expand Up @@ -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;
Expand Down
38 changes: 38 additions & 0 deletions apps/emqx_resource/test/emqx_resource_schema_tests.erl
Expand Up @@ -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
%%===========================================================================
Expand Down
3 changes: 3 additions & 0 deletions changes/ce/fix-11106.en.md
@@ -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.