From cb23a30fe25dbaf5b9a2ff1be87d9e08b1dd9dcb Mon Sep 17 00:00:00 2001 From: Sergey Prokhorov Date: Tue, 14 Apr 2026 02:26:20 +0200 Subject: [PATCH] Warn if 'back' node is not accessible from 'front' --- src/mtproto_proxy_app.erl | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/src/mtproto_proxy_app.erl b/src/mtproto_proxy_app.erl index 773a14d..6434124 100644 --- a/src/mtproto_proxy_app.erl +++ b/src/mtproto_proxy_app.erl @@ -38,12 +38,7 @@ start(_StartType, _StartArgs) -> Role = node_role(), case Role of front -> - case application:get_env(?APP, back_node) of - {ok, BackNode} -> - net_kernel:connect_node(BackNode); - undefined -> - ?LOG_WARNING("node_role=front but back_node is not configured", []) - end; + maybe_connect_back_node(); _ -> ok end, case Role of @@ -181,6 +176,33 @@ start_proxy(#{name := Name, port := Port, secret := Secret, tag := Tag} = P) -> stop_proxy(#{name := Name}) -> ranch:stop_listener(Name). +maybe_connect_back_node() -> + case application:get_env(?APP, back_node) of + {ok, BackNode} -> + connect_back_node(BackNode); + undefined -> + ?LOG_WARNING( + "node_role=front but back_node is not configured; set {back_node, 'back@HOST'} " + "in sys.config and start the back node first", + []) + end. + +connect_back_node(BackNode) -> + case net_kernel:connect_node(BackNode) of + true -> + ok; + false -> + ?LOG_WARNING( + "Failed to connect front node ~p to back node ~p; listeners will keep running " + "and the proxy will retry on demand. Check that the back node is running, " + "back_node matches the back vm.args -name, -setcookie matches on both nodes, " + "and TCP 4369 (epmd) plus the back vm.args -kernel inet_dist_listen_min/" + "inet_dist_listen_max port (for example 9299) are reachable between the two " + "servers; if you use a tunnel or TLS distribution, those settings must carry " + "this same Erlang distribution connection successfully", + [node(), BackNode]) + end. + config_changed(_, ip_lookup_services, _, front) -> ok; config_changed(_, ip_lookup_services, _, _) -> mtp_config:update(); @@ -190,6 +212,8 @@ config_changed(_, proxy_secret_url, _, _) -> config_changed(_, proxy_config_url, _, front) -> ok; config_changed(_, proxy_config_url, _, _) -> mtp_config:update(); +config_changed(Action, back_node, BackNode, front) when Action == new; Action == changed -> + connect_back_node(BackNode); config_changed(Action, max_connections, _, back) when Action == new; Action == changed -> ok; config_changed(Action, max_connections, N, _) when Action == new; Action == changed -> (is_integer(N) and (N >= 0)) orelse error({"max_connections should be non_neg_integer", N}),