Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Ensure no reconnect happens after destroy() #434

Merged
merged 1 commit into from
Oct 12, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/Slackbot_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ module.exports = function(botkit, config) {
}
};

// Set when destroy() is called - prevents a reconnect from completing
// if it was fired off prior to destroy being called
var destroyed = false;
var pingIntervalId = null;
var lastPong = 0;
var retryBackoff = null;
Expand Down Expand Up @@ -97,7 +100,7 @@ module.exports = function(botkit, config) {
botkit.log.notice('** BOT ID:', bot.identity.name, '...reconnect attempt #' +
back.settings.attempt + ' of ' + options.retries + ' being made after ' + back.settings.timeout + 'ms');
bot.startRTM(function(err) {
if (err) {
if (err && !destroyed) {
return reconnect(err);
}
retryBackoff = null;
Expand All @@ -109,6 +112,9 @@ module.exports = function(botkit, config) {
* Shutdown and cleanup the spawned worker
*/
bot.destroy = function() {
// this prevents a startRTM from completing if it was fired off
// prior to destroy being called
destroyed = true;
if (retryBackoff) {
retryBackoff.close();
retryBackoff = null;
Expand All @@ -133,6 +139,12 @@ module.exports = function(botkit, config) {
bot.identity = res.self;
bot.team_info = res.team;

// Bail out if destroy() was called
if (destroyed) {
botkit.log.notice('Ignoring rtm.start response, bot was destroyed');
return cb('Ignoring rtm.start response, bot was destroyed');
}

/**
* Also available:
* res.users, res.channels, res.groups, res.ims,
Expand Down