One of the things you have to be aware when writing a bot is disabled integrations and closed connections. The first case is simple - when someone disables a bot integration, Slack closes a Real Time connection’s WebSocket without an explanation.
The next time you invoke rtm.start, Slack will return account_inactive. Other possible errors include invalid_auth, which is when someone removes an integration instead of disabling it.
The same thing happens when you remove an application (the Remove App button below) that was setup via Slack Button Integration.
A bot framework should handle this gracefully. For example, slack-bot-server, used in playplay.io will attempt to restart a bot on any error, then handle account_inactive or invalid_auth by deactivating the team and not trying to reconnect again. It will also try reactivate the team upon re-registration via Slack Button, too.