diff --git a/core/src/main/resources/com/taobao/arthas/core/http/web-console.js b/core/src/main/resources/com/taobao/arthas/core/http/web-console.js index 8983073bd..7f9486643 100644 --- a/core/src/main/resources/com/taobao/arthas/core/http/web-console.js +++ b/core/src/main/resources/com/taobao/arthas/core/http/web-console.js @@ -105,6 +105,7 @@ function startConnect (silent) { // init webSocket initWs(ip, port); ws.onerror = function () { + ws.close(); ws = null; !silent && alert('Connect error'); }; @@ -128,7 +129,7 @@ function startConnect (silent) { }); ws.send(JSON.stringify({action: 'resize', cols: terminalSize.cols, rows: terminalSize.rows})); window.setInterval(function () { - if (ws != null) { + if (ws != null && ws.readyState === 1) { ws.send(JSON.stringify({action: 'read', data: ""})); } }, 30000); @@ -137,6 +138,7 @@ function startConnect (silent) { function disconnect () { try { + ws.close(); ws.onmessage = null; ws.onclose = null; ws = null; diff --git a/tunnel-server/src/main/resources/static/web-console.js b/tunnel-server/src/main/resources/static/web-console.js index 882178825..02aa5d3fb 100644 --- a/tunnel-server/src/main/resources/static/web-console.js +++ b/tunnel-server/src/main/resources/static/web-console.js @@ -116,6 +116,7 @@ function startConnect (silent) { // init webSocket initWs(ip, port, agentId); ws.onerror = function () { + ws.close(); ws = null; !silent && alert('Connect error'); }; @@ -144,7 +145,7 @@ function startConnect (silent) { }); ws.send(JSON.stringify({action: 'resize', cols: terminalSize.cols, rows: terminalSize.rows})); window.setInterval(function () { - if (ws != null) { + if (ws != null && ws.readyState === 1) { ws.send(JSON.stringify({action: 'read', data: ""})); } }, 30000); @@ -153,6 +154,7 @@ function startConnect (silent) { function disconnect () { try { + ws.close(); ws.onmessage = null; ws.onclose = null; ws = null;