Skip to content

Commit

Permalink
AMBARI-25928: Continuous increase of websocket connections in Ambari …
Browse files Browse the repository at this point in the history
…web UI (#3783)
  • Loading branch information
zRains authored Apr 27, 2024
1 parent d51e6c9 commit 1fb531c
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions ambari-web/app/utils/stomp_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ module.exports = Em.Object.extend({
*/
isConnected: false,

/**
* @type {number | null}
*/
timerId: null,

/**
* @type {boolean}
*/
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
}
},

/**
Expand Down

0 comments on commit 1fb531c

Please sign in to comment.