如何捕获 EventMachine 服务器上的顶级故障?
我有一个 EventMachine 服务器,正在使用 monit 进行监控。有时它会崩溃,我试图找出原因,但我不清楚如何记录所有顶级故障。我尝试了这样的代码:
begin
EventMachine::run do
EventMachine::start_server('0.0.0.0', PORT, MyServer)
end
rescue Exception => e
puts "FAILURE: #{e.class}: #{e}"
end
但这似乎没有捕获错误。我怀疑这可能是内存不足之类的问题,我正在单独跟踪,但如果可能的话,我仍然希望该服务器记录其故障的直接原因。
I have an EventMachine server that I am monitoring with monit. Sometimes it crashes, and I am trying to figure out why, but it is unclear to me how I can just log all top level failures. I tried code like this:
begin
EventMachine::run do
EventMachine::start_server('0.0.0.0', PORT, MyServer)
end
rescue Exception => e
puts "FAILURE: #{e.class}: #{e}"
end
but that does not seem to ever catch errors. I suspect it might be something like running out of memory, which I am tracking separately, but still I would like this server to log its proximate cause of failure if possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想要一个包罗万象的错误处理程序,请尝试 EM.error_handler。 docs 中的示例:
您可能还需要更细粒度的错误处理,在这种情况下您可以使用 errback 机制(请参阅 Deferrable)。例如,您可以在您的反应器循环中使用:
要使其工作,请在 MyServer 中
包含 Deferrable
,然后每当您想引发错误时,调用fail
。If you want a catch-all error handler, try EM.error_handler. Example from the docs:
You may also want more fine-grained error handling, in which case you can use the errback mechanism (see Deferrable). So for example you could have in your reactor loop:
For this to work,
include Deferrable
in your MyServer, then whenever you want to raise an error, callfail
.