-
-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pongbot does not reconnect #107
Comments
If you can reproduce then we probably do have a bug. Could use a test/fix. Thanks. |
Thank you. I can reproduce that WiFi-case error on macOS and Linux (Raspberry PI). I don't know which layer should raise the error. In this case, the client looks still connected, So, I think pong-bot needs to detect the disconnection using a kind of watchdog-mechanism |
Try with a bot that's implemented on top of https://github.com/dblock/slack-ruby-bot-server, I am pretty sure it has reconnect logic that handles it. For example https://github.com/dblock/slack-market. |
Thanks for your kind suggestion. I'll try it. Let me confirm one more thing. |
In theory we should have complete reconnect logic here. So what you described initially still looks like a bug to me, but you'll have to dig through it and possibly PR a fix. |
Maybe, this issue is related with faye/websocket-driver-ruby#42 and celluloid/celluloid-io#176. Also, slack-ruby/slack-ruby-client#96 looks very similar. @tikh reproduced the same situation by turning off his WiFi. One thing different was periodic pining created a catchable exception, while my pongbot is too shy to sending pings. I'm not sure I should make pongbot chatty, or hack celluloid-io. |
I settled to add such ping thread to my pongbot: class PingThread < SlackRubyBot::Server
on 'hello' do |client, data|
puts "PingThread: Hello!"
@reconnect_count ||= 0
if @ping_thread
@ping_thread.exit
@reconnect_count += 1
end
@ping_thread = Thread.new do
sequence = 1
loop do
client.ping({id: sequence})
sleep 30
sequence += 1
end
end
end
end This thread emits |
If you're using Celluloid you might want to change this not to use a thread. You can add |
I'd love for this to be turned into a feature, something that checks bot connections periodically and is built in. |
Thanks for the comment. I've tried to replace thread by class PingThread < SlackRubyBot::Server
extend Celluloid
on 'hello' do |client, data|
puts "PingThread: Hello!"
@reconnect_count ||= 0
if @timer
@timer.cancel
@reconnect_count += 1
end
sequence = 1
@timer = every 30 do
client.ping({id: sequence})
puts "PingThread: ping #{sequence}, reconnect: #{@reconnect_count}."
sequence += 1
end
end
end I had to use |
Looks good to me. |
Thanks. I hope this mechanism becomes a built-in feature. |
I have similar problem, but it's worse as I understand. I have bot running without bot server, just on celluloid by
but no Now I fixed this by listening for the def run
instance.on 'hello', ->(client, data) do
logger.debug "PingThread: Hello!"
@reconnect_count ||= 0
if @timer
@timer.cancel
@reconnect_count += 1
end
@sequence = 1
@timer = every 15 do
if @pong_recieved == false
@pong_recieved = nil
logger.warn 'Pong for previous ping not recieved, restarting.'
instance.instance_variable_set('@client', nil)
instance.restart!
next
end
client.ping(id: @sequence)
logger.debug "PingThread: ping #{@sequence}, reconnect: #{@reconnect_count}."
@pong_recieved = false
end
end
instance.on 'pong', ->(client, data) do
logger.debug "PingThread: Pong received!"
if data['reply_to'] == @sequence
@pong_recieved = true
@sequence += 1
end
end
super
end |
I've recently been doing this. I definitely think we're not properly handling a server-side disconnect, see slack-ruby/slack-ruby-client#208, with someone at Slack looking at helping us. |
To tell the truth, my first version was very similar to @gsmetal 's one like below. class PingThread < SlackRubyBot::Server
extend Celluloid
PONG_ID_QUEUE = []
def self.pong_received?(id)
!PONG_ID_QUEUE.delete(id).nil?
end
on 'hello' do |client, data|
puts "Ping Thread HELLO!"
PONG_ID_QUEUE.clear
@reconnect_count ||= 0
if @timer
@timer.cancel
@reconnect_count += 1
end
sequence = 1
@timer = every 30 do
client.ping({id: sequence})
puts "ping #{sequence}, reconnect: #{@reconnect_count}."
sleep 3
raise Errno::ETIMEDOUT unless pong_received?(sequence)
sequence += 1
end
end
on 'pong' do |client, data|
sequence = data[:reply_to].to_i
puts "pong #{sequence}"
PONG_ID_QUEUE << sequence
end
end |
Hi, I am trying to use the simple pong example but I keep getting this error:
|
Resolved via slack-ruby/slack-ruby-client#208 |
Hi, I'm playing with your slack-ruby-bot in my holiday.
I started from pongbot in README and talked with the bot, it's 👍
However, after several minutes of network disconnection,
I noticed that pongbot does not try to reconnect to Slack.
For example, turn-off my WiFi network, wait several minutes, and then reconnect WiFi,
pongbot is left disconnected even if WiFi is back.
Terminal does not print any line during that experiment.
I believe
handle_exceptions
in server.rb kicksrestart!
.However, it seems not to catch any exception in this situation.
Any hint to add reconnect feature to pongbot ?
I'm using Ruby 2.3.3 and macOS Sierra and slack-ruby-bot 0.9.
Here is the Gemfile.lock for the pongbot
The text was updated successfully, but these errors were encountered: