Skip to content
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

Bot disconnecting, but loop keeps running #13

Open
fliespl opened this issue Sep 25, 2017 · 6 comments
Open

Bot disconnecting, but loop keeps running #13

fliespl opened this issue Sep 25, 2017 · 6 comments

Comments

@fliespl
Copy link

fliespl commented Sep 25, 2017

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?

@mpociot
Copy link
Member

mpociot commented Sep 25, 2017

Hi,

not that I know of. I will need to look into this issue.

@fliespl
Copy link
Author

fliespl commented Sep 26, 2017

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.

@fliespl
Copy link
Author

fliespl commented Oct 3, 2017

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);

@mpociot
Copy link
Member

mpociot commented Oct 3, 2017

That’s great! Do you want to PR this yourself? Otherwise I’ll take care of it later.

@fliespl
Copy link
Author

fliespl commented Oct 3, 2017

@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. :)

@orottier
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants