Search code examples
javascriptslack-apibotkit

error: Error: Stale RTM connection, closing RTM; rtm_close event not triggered


I have created a basic bot and left it connected. After some time, it gave the error Stale RTM connection, closing RTM. The rtm_close event was not fired and the process is still running then why did the bot stop listening.

How to deal with such issues in production? Why is rtm_close event not fired?

Environment: Current version: "version": "0.5.4" (from botkit package.json) OS: macOS Sierra (version: 10.12.4)

Simple code:

function rtmManager(controller, config) {
  var bot = controller.spawn(config);
  bot.startRTM(function(err, bot) {
  if (err) {
    debug('Failed to start RTM')
  }
  } );
  controller.on('rtm_close', function(bot) {
    debug('RTM connection is closed');
  });
  return bot;
}
var Botkit = require('botkit');
var bot_options = {
   debug : process.env.DEBUG || false,
};
var controller = Botkit.slackbot(bot_options);
controller.startTicking();
rtmManager(controller, {token: process.env.SLACK_TOKEN});

enter image description here


Solution

  • In fact, rtm_close callback is invoked but it was throwing an error which is no where caught. So, it seems not called.