From c38944e9485032e0f6144b6e030db9adb78bd498 Mon Sep 17 00:00:00 2001 From: Lykin <137850705+tiny-craft@users.noreply.github.com> Date: Thu, 15 Aug 2024 12:33:51 +0800 Subject: [PATCH] fix: stop command monitor may block ui (#326) --- backend/services/monitor_service.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/services/monitor_service.go b/backend/services/monitor_service.go index 43d0e68..fc0e82c 100644 --- a/backend/services/monitor_service.go +++ b/backend/services/monitor_service.go @@ -89,7 +89,7 @@ func (c *monitorService) StartMonitor(server string) (resp types.JSResp) { item.cmd = item.client.Monitor(c.ctx, item.ch) item.cmd.Start() - go c.processMonitor(&item.mutex, item.ch, item.closeCh, item.eventName) + go c.processMonitor(&item.mutex, item.ch, item.closeCh, item.cmd, item.eventName) resp.Success = true resp.Data = struct { EventName string `json:"eventName"` @@ -99,7 +99,7 @@ func (c *monitorService) StartMonitor(server string) (resp types.JSResp) { return } -func (c *monitorService) processMonitor(mutex *sync.Mutex, ch <-chan string, closeCh <-chan struct{}, eventName string) { +func (c *monitorService) processMonitor(mutex *sync.Mutex, ch <-chan string, closeCh <-chan struct{}, cmd *redis.MonitorCmd, eventName string) { lastEmitTime := time.Now().Add(-1 * time.Minute) cache := make([]string, 0, 1000) for { @@ -120,6 +120,7 @@ func (c *monitorService) processMonitor(mutex *sync.Mutex, ch <-chan string, clo case <-closeCh: // monitor stopped + cmd.Stop() return } } @@ -136,7 +137,6 @@ func (c *monitorService) StopMonitor(server string) (resp types.JSResp) { return } - item.cmd.Stop() //close(item.ch) close(item.closeCh) delete(c.items, server)