0
我想SSE功能添加到使用的Redis PubSub的我的服务器应用程序,通过多篇文章指导即: how-to-use-actioncontollerlive-along-with-resque-redis。无法处理断开连接的客户SSE
服务器中的Heroku托管,从而心跳是必要的,以及。
...
sse = SSE.new(response.stream)
begin
redis = Redis.new(:url => ENV['REDISCLOUD_URL'])
redis.subscribe(<UUID>, HEARTBEAT_CHANNEL) do |on|
on.message do |channel, data|
begin
if channel == HEARTBEAT_CHANNEL
sse.write('', event: "hb")
else
sse.write(data, event: "offer_update")
end
rescue StandardError => e #I'll call this section- "internal rescue"
puts "Internal: #{$!}"
redis.quit
sse.close
puts "SSE was closed
end
end
end
rescue StandardError => e #I'll call this section- "external rescue"
puts "External: #{$!}"
ensure
redis.quit
sse.close
puts "sse was closed"
end
的问题:
- 我没有看到任何地方的 “内部救助” 过网谈SSE。但是如果由
sse.write
引发,我不会得到哪些人可以发现异常?常见的情况是HB发送时客户端不再连接,这使得这部分非常关键(出现"Internal: client disconnected"
)。我对吗? - 在这种情况下,将“外部救援”被触发?客户端断开是否导致
sse.write
在“内部块”(on.message内部)中引发异常?因为当我试图模拟它几十次时,它从未被外部救援所捕获。 - 此代码也受到影响。内部营救部分的
redis.quit
引发了另一个由外部营救声明捕获的异常:External: undefined method 'disconnect' for #<Redis::SubscribedClient:0x007fa8cd54b820>
。所以 - 它应该怎么做?我如何才能识别客户端断开,以释放内存&套接字? - 怎么能够由
sse.write
引起的异常没有被外部救援陷入(因为它应该是从开始),而另一个错误(我的第三个问题中所述)已经被抓住?所有这些代码(outer + inner部分)都在同一个线程中运行,对吧?我很乐意进行深入的解释。