From d5b7b9c2a4350542c514d505e868591618913e0b Mon Sep 17 00:00:00 2001 From: Martin Sumner Date: Sat, 6 Jul 2024 10:15:46 +0100 Subject: [PATCH 1/3] Remove client/server only options --- src/riak_repl_tcp_server.erl | 2 +- src/riak_repl_util.erl | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/riak_repl_tcp_server.erl b/src/riak_repl_tcp_server.erl index 78a6dfdb..1cdacb6d 100644 --- a/src/riak_repl_tcp_server.erl +++ b/src/riak_repl_tcp_server.erl @@ -346,7 +346,7 @@ send_peerinfo(#state{transport=Transport, socket=Socket, sitename=SiteName} = St OurNode -> _ = erlang:cancel_timer(State#state.election_timeout), %% are we configured to upgrade to ssl? - case {riak_repl_util:maybe_use_ssl(), Transport:name()} of + case {riak_repl_util:maybe_server_use_ssl(), Transport:name()} of {B, T} when B == false; T == ssl -> %% if there's no valid ssl config or we've already %% upgraded diff --git a/src/riak_repl_util.erl b/src/riak_repl_util.erl index 72fa2289..f7fd8f9d 100644 --- a/src/riak_repl_util.erl +++ b/src/riak_repl_util.erl @@ -30,6 +30,7 @@ normalize_ip/1, format_socketaddrs/2, maybe_use_ssl/0, + maybe_server_use_ssl/0, upgrade_client_to_ssl/1, choose_strategy/2, strategy_module/2, @@ -471,12 +472,34 @@ validate_ssl_config(true, [{cacerts, CACerts}|Rest]) -> validate_ssl_config(true, [_|Rest]) -> validate_ssl_config(true, Rest). +client_only_options() -> + [server_name_indication]. + +server_only_options() -> + [fail_if_no_peer_cert]. + +deduct_options(StandardOptions, SpecificOptions) -> + lists:foldl( + fun(K, CfgAcc) -> + lists:keydelete(K, 1, CfgAcc) + end, + StandardOptions, + SpecificOptions). + upgrade_client_to_ssl(Socket) -> case maybe_use_ssl() of false -> {error, no_ssl_config}; Config -> - ssl:connect(Socket, Config) + ssl:connect(Socket, deduct_options(Config, server_only_options())) + end. + +maybe_server_use_ssl() -> + case maybe_use_ssl() of + false -> + false; + Config -> + deduct_options(Config, client_only_options()) end. load_certs(undefined) -> From 6a1cf55dbad24a8c4ee418f6c27cc3941509d1af Mon Sep 17 00:00:00 2001 From: Martin Sumner Date: Sat, 6 Jul 2024 10:17:13 +0100 Subject: [PATCH 2/3] Fail cancelled connection when a connection has been cancelled, it will be remove. This has been changed to now fail the request as part of the removal. This will inform any process that requested the connection, rather than have it stuck waiting for a socket. --- src/riak_core_connection_mgr.erl | 43 +++++++++++++++++++------------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/src/riak_core_connection_mgr.erl b/src/riak_core_connection_mgr.erl index 5154095c..9b0858ec 100644 --- a/src/riak_core_connection_mgr.erl +++ b/src/riak_core_connection_mgr.erl @@ -433,32 +433,39 @@ disconnect_from_target(Target, State = #state{pending = Pending}) -> Req -> case get_cancellation_interval() of undefined -> - ?LOG_WARNING("Cancelled connection ~p will not be removed because - cm_cancellation_interval is set to undefined", [Req#req.target]); + ?LOG_WARNING( + "Cancelled connection ~p will not be removed because" + "cm_cancellation_interval is set to undefined", + [Req#req.target] + ); Interval when is_integer(Interval) -> - erlang:send_after(Interval,self(),{remove_cancelled_connection,Req#req.ref}); + erlang:send_after( + Interval, + self(), + {remove_cancelled_connection, Req} + ); Error -> - ?LOG_ERROR("Unsupported cm_cancellation_interval: ~p", [Error]) + ?LOG_ERROR( + "Unsupported cm_cancellation_interval: ~p", + [Error] + ) end, %% The helper process will discover the cancellation when it asks if it %% should connect to an endpoint. - State#state{pending = lists:keystore(Req#req.ref, #req.ref, Pending, - Req#req{state = cancelled})} + State#state{ + pending = + lists:keystore( + Req#req.ref, + #req.ref, + Pending, + Req#req{state = cancelled} + ) + } end. %% @doc remove pending connection from state for supplied Ref. -remove_cancelled_connection(Ref, State = #state{pending = Pending}) -> - case lists:keytake(Ref, #req.ref, Pending) of - false -> - State; - {value, Req, Pending2} -> - case Req#req.state of - cancelled -> - State#state{pending=Pending2}; - _ -> - State - end - end. +remove_cancelled_connection(Req, State) -> + fail_request(cancelled, Req, State). %% schedule a retry to occur after Interval milliseconds. %% do not clear the pid from pending. the exit handler will do that. From e6b86f9647a5dfd8ff5e7bc22f47ae4acaf8e035 Mon Sep 17 00:00:00 2001 From: Martin Sumner Date: Fri, 20 Sep 2024 08:57:43 +0100 Subject: [PATCH 3/3] Update riak_kv reference (now changes merged) --- rebar.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rebar.config b/rebar.config index 8d087eb9..e00c2ce8 100644 --- a/rebar.config +++ b/rebar.config @@ -24,7 +24,7 @@ {ranch, {git, "https://github.com/ninenines/ranch.git", {tag, "1.8.0"}}}, {ebloom, {git, "https://github.com/nhs-riak/ebloom.git", {branch, "nhse-develop"}}}, {folsom, {git, "https://github.com/nhs-riak/folsom.git", {branch, "nhse-develop-3.4"}}}, - {riak_kv, {git, "https://github.com/nhs-riak/riak_kv.git", {branch, "nhse-d34-otp26"}}} + {riak_kv, {git, "https://github.com/nhs-riak/riak_kv.git", {branch, "nhse-develop-3.4"}}} ]}. {plugins, [{rebar3_gpb_plugin, {git, "https://github.com/nhs-riak/rebar3_gpb_plugin", {branch, "nhse-develop"}}},