Closed LouisKottmann closed 4 years ago
What's the stack for that status? I would get a backtrace first for when this happens.
Compare with https://github.com/slack-ruby/slack-ruby-bot-server/blob/0b8bbbba45a2b07f35b223b4c18ec86888fc0f49/lib/slack-ruby-bot-server/service.rb, you might be accidentally looping very quickly when you get disconnected and need to reconnect, or something like that.
How do you suggest I get a backtrace?
I have fixed my code to call stop!
after I'm done with a new client, maybe that will solve the issue.
Maybe the clients never got GC'd and I'd increasingly had more and more clients connecting.
How do you suggest I get a backtrace?
Add a begin/rescue
around start_async
to begin with, but otherwise find where that message is emitted from and walk backwards from there to see what calls it, etc.
I have fixed my code to call
stop!
after I'm done with a new client, maybe that will solve the issue. Maybe the clients never got GC'd and I'd increasingly had more and more clients connecting.
That's possible.
I will do that if I see the error again, and close this ticket otherwise. Thank you for your time.
The error did not appear again, so it was me calling an extra:
client = SlackRubyBot::Client.new(token: ENV['SLACK_API_TOKEN'])
client.start_async
for background jobs, and letting it getting GC'd witout further action. This would make clients pile up and eventually getting rate limited when they all tried reconnecting.
While in fact I should have called this when I was done with temporary clients:
client.stop!
I now use an ensure block like so:
def self.with_client_and_data_or_new(client, data)
if client.nil? || data.nil?
begin
client = self.get_new_client
channel = self.get_channel_by_name(client, 'any_chan_name')
data = self.wrap_in_data_object(channel: channel.id,
user: MY_BOT_USERID)
yield(client, data)
ensure
client.stop!
client = nil
end
else
yield(client, data)
end
end
private
def self.get_channel_by_name(client, channel_name)
client
&.channels
&.select { |k, chan| chan['name'] == channel_name }
&.map { |id, info| info }
&.first
end
def self.wrap_in_data_object(channel: nil, user: nil)
Hashie::Mash.new({ channel: channel, user: user})
end
def self.get_new_client
client = SlackRubyBot::Client.new(token: ENV['SLACK_API_TOKEN'])
client.start_async
10.times do
break if client.started?
sleep 1
end
sleep 1
client
end
that I use like this:
with_client_and_data_or_new(client, data) do |c, d|
# do something with c(lient) & d(ata)
end
Is that a good approach or did I miss something obvious?
Does your background job need an RTM client that's listening on Slack events? If you're trying to call some methods like listing channels, instantiate a Slack::Web::Client.new(token: ...)
and call whatever you need. There will be nothing to shutdown.
Right, that looks like the obvious way to do it. Thank you.
Hello,
I have been using this project for a while, and switched a couple months ago to async-websocket as recommended (for better reliability than Celluloid, which we had issues with indeed).
Recently, I have been getting more and more of these in the logs while the bot is idle:
My Gemfile has:
My bot is defined like this:
And I start the bot like this:
What could cause the rate limiting errors? Am I the only one with this issue?
I use this code to create a client for background tasks:
Maybe this is problematic?