diff --git a/ambari-web/app/utils/stomp_client.js b/ambari-web/app/utils/stomp_client.js index 8d4b95b5fe8..cb0af27770f 100644 --- a/ambari-web/app/utils/stomp_client.js +++ b/ambari-web/app/utils/stomp_client.js @@ -58,6 +58,11 @@ module.exports = Em.Object.extend({ */ isConnected: false, + /** + * @type {number | null} + */ + timerId: null, + /** * @type {boolean} */ @@ -157,9 +162,13 @@ module.exports = Em.Object.extend({ }, reconnect: function(useSockJS) { + if (this.timerId !== null) { + clearTimeout(this.timerId); + } const subscriptions = Object.assign({}, this.get('subscriptions')); - setTimeout(() => { + this.timerId = setTimeout(() => { console.debug('Reconnecting to WebSocket...'); + this.disconnect(); this.connect(useSockJS).done(() => { this.set('subscriptions', {}); for (let i in subscriptions) { @@ -173,7 +182,10 @@ module.exports = Em.Object.extend({ }, disconnect: function () { - this.get('client').disconnect(); + var client = this.get('client'); + if (client.ws.readyState === client.ws.OPEN) { + client.disconnect(); + } }, /**