mirror of
https://github.com/veops/oneterm.git
synced 2025-09-27 11:42:08 +08:00
fix(backend): resolve exit command delay
This commit is contained in:
@@ -380,6 +380,8 @@ func HandleTerm(sess *gsession.Session, ctx *gin.Context) (err error) {
|
|||||||
protocols.Write(sess)
|
protocols.Write(sess)
|
||||||
return
|
return
|
||||||
case <-chs.AwayChan:
|
case <-chs.AwayChan:
|
||||||
|
// Flush any remaining output before terminating
|
||||||
|
protocols.Write(sess)
|
||||||
return
|
return
|
||||||
case <-sess.IdleTk.C:
|
case <-sess.IdleTk.C:
|
||||||
msg := (&myErrors.ApiError{Code: myErrors.ErrIdleTimeout, Data: map[string]any{"second": model.GlobalConfig.Load().Timeout}}).MessageWithCtx(ctx)
|
msg := (&myErrors.ApiError{Code: myErrors.ErrIdleTimeout, Data: map[string]any{"second": model.GlobalConfig.Load().Timeout}}).MessageWithCtx(ctx)
|
||||||
|
@@ -87,15 +87,17 @@ func connectDB(sess *gsession.Session, asset *model.Asset, account *model.Accoun
|
|||||||
// Log process exit - only log as error if there was an actual error
|
// Log process exit - only log as error if there was an actual error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.L().Error("Database client process exited with error", zap.Error(err), zap.String("protocol", protocol))
|
logger.L().Error("Database client process exited with error", zap.Error(err), zap.String("protocol", protocol))
|
||||||
|
// Only send termination message for error exits
|
||||||
|
if atomic.CompareAndSwapInt32(&exitMessageSent, 0, 1) {
|
||||||
|
terminationMsg := "\r\n\033[31mThe connection is closed!\033[0m\r\n"
|
||||||
|
chs.OutBuf.WriteString(terminationMsg)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.L().Info("Database client process exited normally", zap.String("protocol", protocol))
|
logger.L().Info("Database client process exited normally", zap.String("protocol", protocol))
|
||||||
}
|
// For normal exit, don't send any additional message
|
||||||
|
// The client (redis, mysql, etc.) will have already shown its own exit message
|
||||||
// Only send termination message if not already sent
|
// Mark that exit message has been "sent" to prevent any error message
|
||||||
if atomic.CompareAndSwapInt32(&exitMessageSent, 0, 1) {
|
atomic.StoreInt32(&exitMessageSent, 1)
|
||||||
// Send termination message
|
|
||||||
terminationMsg := "\r\n\033[31mThe connection is closed!\033[0m\r\n"
|
|
||||||
chs.OutBuf.WriteString(terminationMsg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sess.Once.Do(func() {
|
sess.Once.Do(func() {
|
||||||
@@ -166,9 +168,8 @@ func connectDB(sess *gsession.Session, asset *model.Asset, account *model.Accoun
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark exit message as sent, but don't send it here
|
// Let the client process the exit command naturally
|
||||||
atomic.StoreInt32(&exitMessageSent, 1)
|
// The client will display its own exit message (e.g., "Goodbye!" for redis)
|
||||||
|
|
||||||
inputBuffer = ""
|
inputBuffer = ""
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user