driver-slack
driver-slack copied to clipboard
Bot disconnecting, but loop keeps running
Hi Marcel, quick question - is slack driver stable enough to be used in production env?
In our case we have noticed that every 2-3 days Slack Bot (Apps) is being marked as disconnected in channel.
Command line script is no killed though, there is no error in command line output (I believe periodic timer executes as well, but need to double check on that).
Our only option is to kill command and restart it. Any advice?
Hi,
not that I know of. I will need to look into this issue.
I have added locally ping / pong support to websocket and I am waiting for results (if bot gets inactive on slack).
Will let you know in 2-3 days if this could be the possible resolution.
It seems that ping / pong on websocket fixed my issue.
Extended cleitn with: getWebSocket method:
class RealTimeClient extends \Slack\RealTimeClient
{
public function getWebSocket()
{
return $this->websocket;
}
}
And used such code in a loop periodic timer:
/** @var \AppBundle\Drivers\Slack\RealTimeClient $client */
$client = $botMan->getClient();
$client->on('pong', function($data) use($command, $output) {
$command->awaitingPings = 0;
});
$command = $this;
$checkConnection = function() use($client, $output, $command) {
if(!$client->isConnected()) {
$output->writeln(date('[Y-m-d H:i:s]').' - Not connected');
throw new \Exception('Not connected');
}
$id = 'ping:'.time();
$data = [
'id' => $id,
'type' => 'ping'
];
$client->getWebSocket()->send(json_encode($data));
if($command->awaitingPings >= 5) {
throw new \Exception('Too many incomplete pings');
}
$command->awaitingPings++;
$memory = memory_get_usage();
$output->writeln(sprintf('[%s] Missed pings: %s, Memory usage.: %.02f KByte',
date('Y-m-d H:i:s'),
$command->awaitingPings,
$memory / 1024));
};
$loop->addPeriodicTimer(120, $checkConnection);
That’s great! Do you want to PR this yourself? Otherwise I’ll take care of it later.
@mpociot this code is more like a PoC than real solution that can be merged.
I will try to get to it later this week, do some refactoring and PR. :)
Hi, I'm experiencing the same issue. The loop keeps running but after a few days the bot does not respond anymore. @fliespl did you ever get to creating a patch?