Merge pull request #11512 from lafirest/fix/ldap_def_port

fix(ldap): expose request_timeout to prevent infinite hang
This commit is contained in:
lafirest 2023-08-25 10:22:44 +08:00 committed by GitHub
commit ba9cb0a1ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 3 deletions

View File

@ -70,7 +70,12 @@ fields(config) ->
example => <<"(& (objectClass=mqttUser) (uid=${username}))">>,
validator => fun emqx_schema:non_empty_string/1
}
)}
)},
{request_timeout,
?HOCON(emqx_schema:timeout_duration_ms(), #{
desc => ?DESC(request_timeout),
default => <<"5s">>
})}
] ++ emqx_connector_schema_lib:ssl_fields().
server() ->
@ -161,10 +166,15 @@ do_get_status(Conn) ->
%% ===================================================================
connect(Options) ->
#{hostname := Host, username := Username, password := Password} =
#{
hostname := Host,
username := Username,
password := Password,
request_timeout := RequestTimeout
} =
Conf = proplists:get_value(options, Options),
OpenOpts = maps:to_list(maps:with([port, sslopts], Conf)),
case eldap:open([Host], [{log, fun log/3} | OpenOpts]) of
case eldap:open([Host], [{log, fun log/3}, {timeout, RequestTimeout} | OpenOpts]) of
{ok, Handle} = Ret ->
case eldap:simple_bind(Handle, Username, Password) of
ok -> Ret;

View File

@ -23,4 +23,10 @@ The syntax of the filter follows RFC 4515 and also supports placeholders."""
filter.label:
"""Filter"""
request_timeout.desc:
"""Sets the maximum time in milliseconds that is used for each individual request."""
request_timeout.label:
"""Request Timeout"""
}