什么代码将从 ** 删除(超时)连接 ** 中恢复?

What code will recover from ** Removing (timedout) connection **?

我在一个系统上有一个 gen_server,在另外 4 个系统上有 4 个客户端。当 gen_server 报告“** 正在删除(超时)连接 **”时,代码按预期运行 3 或 4 天。因为客户端可以在 gen_server 开始之前或之后变为活动状态,所以客户端在每次调用 gen_server 之前执行此代码:

connect_IPDB() ->
% try every 5 sec to connect to the server
case net_kernel:connect_node(?SERVER) of
    % When connected wait an additional 5 seconds for stablilty
    true -> timer:sleep(5000);
    false -> 
        timer:sleep(5000),
        connect_IPDB()
end.

在以任何顺序启动服务器或客户端时,这按预期工作。当在服务器上执行时,它们都连接并显示在 nodes() 中。

问题来了。在出现“** Removing (timedout) connection **”错误后的某个时间,nodes() 显示了所有节点,这意味着客户端没有挂起并执行了上述代码。但是与超时节点的通信尚未恢复。如何在不重新启动客户端的情况下重新建立连接?顺便说一句,重新启动客户端确实解决了这个问题。

任何帮助,不胜感激。

我终于找到了问题和解决方案。我的超时是在相关客户端暂停(它们是虚拟机)时引起的,因此可以对其进行备份。因为它们被暂停了,当它们被取消暂停时,客户端的主管没有看到任何问题,所以不会重新启动程序。

解决方法是将 connect_IPMD 更改为:

connect_IPDB() ->
% See if we are connected to the server. Is the server in the list?
case lists:filter(fun(X) -> string:str(atom_to_list(X),atom_to_list(?SERVER))== 1 end, nodes(connected)) of
    % If empty, then not in list, enter the reconnect loop
    [] -> 
        connect_IPDB("Reconnect");
    % any thing else, then we are connected, so proceed
    _ -> ok 
end.
connect_IPDB(_Reconnect) ->
case net_kernel:connect_node(?SERVER) of
    % When connected wait an additional 5 seconds for stablilty
    true -> 
        timer:sleep(5000),
        Ips = gen_server:call({global, ?SERVER},getall_ips),
        % Re-initialize the iptables
        removechain(),
        createchain(),
        % Load the Ips into the local iptables f2bchain
        load_ips(Ips),
        % restart the ntpd 
        os:cmd("service ntpd restart");
    false -> 
        timer:sleep(5000),
        connect_IPDB("Reconnect")
end.

当客户端从暂停中恢复时,这具有重置客户端时钟(重新启动 NTPD)的额外优势。

我要让主管去处理 "real" 失败,而不是这种自我引发的失败。