From 8773fd3c3dc3c8bde222dec08161e3a9c27bd805 Mon Sep 17 00:00:00 2001 From: Eugen C Date: Fri, 21 Jun 2019 00:26:08 +0100 Subject: [PATCH] Emit token expiry event 1s earlier This allows re-request st2 token in advance, instead of trying to get it when it's _already_ expired. Add here HTTP request/response time to communicate token update and it leads to issues and races like https://github.com/StackStorm/st2/issues/4119 https://github.com/StackStorm/hubot-stackstorm/pull/178#discussion_r296029876 https://github.com/StackStorm/hubot-stackstorm/issues/157 --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 7fb6dbc..7da2f43 100644 --- a/index.js +++ b/index.js @@ -189,7 +189,7 @@ module.exports = function (opts) { } this._expiryTimeout = setTimeout(function () { this.emit('expiry', token); - }.bind(this), new Date(token.expiry) - new Date()); + }.bind(this), new Date(token.expiry) - new Date() - 1000); return token; }.bind(this)); }