另一个节点发生错误后,erlang节点中的错误 [英] a bug in erlang node after an error at another node

查看:57
本文介绍了另一个节点发生错误后,erlang节点中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在同一台Windows计算机上用两个cmd窗口创建了2个erlang节点:'unclient @ MYPC'和'unserveur @ MYPC',服务器代码非常简单:

i created 2 erlang nodes in the same Windows machine with two cmd windows:'unclient@MYPC' and 'unserveur@MYPC' , the server code is very simple :

-module(serveur).
-export([start/0,recever/0,inverse/1]). 
%%%%
start() -> 
process_flag(trap_exit,true), 
Pid=spawn_link(serveur,recever,[]), 
register(ownServer, Pid). 
%%%%
recever() -> 
receive 
{From, X} ->From ! {ownServer,1/X} 
end. 
%%%%
inverse(X) -> 
ownServer!{self(), X}, 
receive 
{'EXIT',_, _} ->start(), 
                sorry;

{ownServer, Reply} ->Reply 
end. 

因此在服务器节点cmd上,我启动了此模块

so at the server node cmd i start this module

c(serveur). 
serveur:start(). 

我测试了该服务器:在我使用的服务器节点cmd上:

and i tested this server :at the server node cmd i used :

apply(serveur,inverse,[2]).

我收到0.5,我也尝试通过使用原子代替数字来引起错误:

and i received 0.5 and i tried too causing an error by using an atom in the place of a number :

apply(serveur,inverse,[a]).

外壳程序显示错误并显示对不起,并且服务器通过重新启动来正常工作他的孩子会自动进入系统,因为这是系统过程,因此他会诱捕孩子的出口。

and the shell shows the error and shows 'sorry' and the server returns to its work correctly by restarting his child automatically because it is a system process and he traps the exit of his child.

现在在客户端节点上,我使用rpc调用函数尝试连接,并且一切都很好,例如,我尝试了:

now at the client node i used the rpc call function to try the connection and all is fine, for example i try :

rpc:call('unserveur@MYPC' ,serveur,inverse,[2]).

在客户端节点cmd上,我收到:0.5

and at the client node cmd i receive :0.5

现在我使用原子将其发送到服务器,从而导致错误

now i use an atom to send it to the server for causing an error

rpc:call('unserveur@MYPC' ,serveur,inverse,[a]).

在客户端cmd节点上:
i等待服务器的响应,该响应应为'抱歉,但我什么也没收到,客户端提示也没有:

at the client cmd node : i waited for the response from the server that should be 'sorry' but i didn't receive anything and there is no more the client prompt :

unclient@MYPC 1>

我可以写,但是shell不再执行我的指令了,也没有任何提示。服务器节点上的

i看到错误,然后服务器提示符正常返回

i can write but the shell does not execute my instructions anymore and there is not any prompt. at the server node : i see an error and then the server prompt returns normally

unserveur@MYPC 5>

我在服务器节点提示符下尝试过此操作:

i tried this at the server node prompt :

apply(serveur, inverse, [2]).

,我遇到了一个错误,因此我通过调用start()函数手动重新启动服务器。服务器节点cmd,然后服务器恢复正常工作。
我在客户端调用之前和之后和pid上在服务器节点cmd上尝试了self(),这是逻辑上的,因为主服务器进程是系统进程,所以我的结果是他没有执行代码收到{'EXIT',...}。
为什么会发生?我听不懂这个错误,所以任何人都可以向我解释一下发生了什么?

and i had an error, so i restart the server manually by calling the start() function at the server node cmd and after that the server returns to work normally. I tried self() on the server node cmd before and after the client call and the pid is the same and this is logic because the main server process is a system process so my result that he didn't execute the code after receive {'EXIT',...}. why that happens ? i couldn't understand this bug so any one can explain to me please what that happens ?

推荐答案

之所以会发生这种情况,是因为 EXIT 消息发送到了链接到服务器进程,而该服务器进程不一定与发送消息的进程相同。

This happens because the EXIT message is sent to any process that is linked to the server process, which is not necessarily the same process that sent the message.

当您在shell中运行它时,它可以工作,因为shell进程已被链接到服务器进程,而shell进程也是调用 inverse 函数的进程。但是,当您进行RPC调用时, inverse 函数是从另一个进程中调用的。

It works when you run it in the shell, since the shell process gets linked to the server process, and the shell process is also the one that calls the inverse function. However, when you make an RPC call, the inverse function is called from a different process.

尝试进行从客户端进行RPC调用,然后在服务器节点的外壳中运行 flush()。,您应该看到 EXIT 消息。

Try making the RPC call from the client, and then running flush(). in the shell of the server node, and you should see the EXIT message.

这篇关于另一个节点发生错误后,erlang节点中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆