From 79eb0288b4bfb38e8b253fceb85406f2a8afb210 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Wed, 19 Mar 2025 11:43:21 +0800 Subject: [PATCH] fix: Fix the problem that the terminal exit fails (#8189) --- backend/app/api/v1/terminal.go | 11 +++++------ backend/utils/terminal/local_cmd.go | 1 + frontend/src/components/terminal/index.vue | 10 ++++++---- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/backend/app/api/v1/terminal.go b/backend/app/api/v1/terminal.go index c92fa7d9f..5d32248b9 100644 --- a/backend/app/api/v1/terminal.go +++ b/backend/app/api/v1/terminal.go @@ -68,9 +68,8 @@ func (b *BaseApi) WsSsh(c *gin.Context) { <-quitChan - if wshandleError(wsConn, err) { - return - } + dt := time.Now().Add(time.Second) + _ = wsConn.WriteControl(websocket.CloseMessage, nil, dt) } func (b *BaseApi) ContainerWsSSH(c *gin.Context) { @@ -133,9 +132,9 @@ func (b *BaseApi) ContainerWsSSH(c *gin.Context) { <-quitChan global.LOG.Info("websocket finished") - if wshandleError(wsConn, err) { - return - } + dt := time.Now().Add(time.Second) + _ = wsConn.WriteControl(websocket.CloseMessage, nil, dt) + } func loadRedisInitCmd(c *gin.Context) (string, string, error) { diff --git a/backend/utils/terminal/local_cmd.go b/backend/utils/terminal/local_cmd.go index d0926fd69..eaf96c6fc 100644 --- a/backend/utils/terminal/local_cmd.go +++ b/backend/utils/terminal/local_cmd.go @@ -100,4 +100,5 @@ func (lcmd *LocalCommand) Wait(quitChan chan bool) { global.LOG.Errorf("ssh session wait failed, err: %v", err) setQuit(quitChan) } + setQuit(quitChan) } diff --git a/frontend/src/components/terminal/index.vue b/frontend/src/components/terminal/index.vue index 2ac20c920..c599a6707 100644 --- a/frontend/src/components/terminal/index.vue +++ b/frontend/src/components/terminal/index.vue @@ -85,7 +85,9 @@ function onClose(isKeepShow: boolean = false) { term.value.dispose(); } catch {} } - terminalElement.value.innerHTML = ''; + if (terminalElement.value) { + terminalElement.value.innerHTML = ''; + } } // terminal 相关代码 start @@ -202,10 +204,10 @@ const errorRealTerminal = (ex: any) => { const closeRealTerminal = (ev: CloseEvent) => { if (heartbeatTimer.value) { - clearInterval(heartbeatTimer.value); + clearInterval(Number(heartbeatTimer.value)); } - term.value.write('The connection has been disconnected.'); - term.value.write(ev.reason); + term.value?.write('The connection has been disconnected.'); + term.value?.write(ev.reason); }; const isWsOpen = () => {