Erlang gen_服务器在httpc调用后未获取消息
我有一个进程向gen_服务器发送暂停消息,如下所示:Erlang gen_服务器在httpc调用后未获取消息,erlang,gen-server,Erlang,Gen Server,我有一个进程向gen_服务器发送暂停消息,如下所示: Results = [gen_server:cast(Child, pause) || {Id, Child, _Type, _Modules} <- supervisor:which_children(?SERVER), ?IGNORE(Id) == false], 真正奇怪的是,我的gen_服务器中有一台似乎经常没有收到暂停消息——我没有收到更大的消息,并且所讨论的进程不会响应后续的暂停(或恢复)尝试 对
Results = [gen_server:cast(Child, pause) ||
{Id, Child, _Type, _Modules} <- supervisor:which_children(?SERVER),
?IGNORE(Id) == false],
真正奇怪的是,我的gen_服务器中有一台似乎经常没有收到暂停消息——我没有收到更大的消息,并且所讨论的进程不会响应后续的暂停(或恢复)尝试
对可能发生的事情有什么想法吗
gen_服务器非常简单,它使用erlang:send_after/3向自己发送“poll”消息。收到此轮询消息后,如果未暂停,它将点击一个url并将响应保存到ETS,并触发另一个erlang:send_after/3,以便在适当的时间间隔后再次轮询。如果它暂停,它只会触发另一个erlang:send_after?3
pause所做的一切都是将状态设置为paused=true
使用observer,卡住的进程显示当前函数为httpc:handle\u answer,消息队列正在备份
状态选项卡:信息“超时”
提示“此进程可能不会处理系统消息”
堆栈顶部的跟踪显示
httpc:handle\u answer httpc.erl:636我从以下位置选择了httpc:handle\u answer的代码: (注意:它与您的版本不同,因为函数从第616行到第631行)
因此,进程正在等待一条消息(在调用
httpc\u管理器:request(request,profile\u name(profile)
,该消息返回了{ok,RequestId}),并且此消息没有出现或格式错误。您能检查参数值和消息队列吗?包含字符串以外的值的标头导致httpc\u处理程序退出。但在此之后,调用方在httpc:handle\u answer/3中的“receive”处永久挂起,因为没有向调用方发送任何消息
你可以用这个来测试
Request1= {"http://www.google.com",[{"cookie",undefined}, {"test",123}],"application/x-www-form-urlencoded; charset=utf-8", <<"">>}.
httpc:request(post, Request1, [{timeout,1000}], []).
Request1={”http://www.google.com“,[{“cookie”,未定义,{“test”,123}],“application/x-www-form-urlencoded;charset=utf-8”,}。
httpc:request(post,Request1,[{timeout,1000}],]。
您确定进程仍然存在吗?宏是什么?忽略?是否有可能进程在同步调用中永远等待?它仍然存在,主管:哪些子进程列出了子进程,子进程随后可以通过主管:终止,所有?忽略宏是否查看Id是否为在一个永远不应该暂停的孩子列表中,您是否使用appmon之类的工具来检查进程的状态?添加到OP中,我看到Observerhttp请求没有返回,它被卡在接收中。在我的客户端中,我使用了默认的httpc超时,即无限。我将其更改为30000,我认为这解决了问题te回答,但今天有这个问题:)
handle_answer(RequestId, false, _) ->
{ok, RequestId};
handle_answer(RequestId, true, Options) ->
receive
{http, {RequestId, saved_to_file}} ->
?hcrt("received saved-to-file", [{request_id, RequestId}]),
{ok, saved_to_file};
{http, {RequestId, {_,_,_} = Result}} ->
?hcrt("received answer", [{request_id, RequestId},
{result, Result}]),
return_answer(Options, Result);
{http, {RequestId, {error, Reason}}} ->
?hcrt("received error", [{request_id, RequestId},
{reason, Reason}]),
{error, Reason}
end.
Request1= {"http://www.google.com",[{"cookie",undefined}, {"test",123}],"application/x-www-form-urlencoded; charset=utf-8", <<"">>}.
httpc:request(post, Request1, [{timeout,1000}], []).