Skip to content

Commit

Permalink
fix: stop command monitor may block ui (tiny-craft#326)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiny-craft committed Aug 15, 2024
1 parent 5efbd4d commit c38944e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions backend/services/monitor_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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 {
Expand All @@ -120,6 +120,7 @@ func (c *monitorService) processMonitor(mutex *sync.Mutex, ch <-chan string, clo

case <-closeCh:
// monitor stopped
cmd.Stop()
return
}
}
Expand All @@ -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)
Expand Down

0 comments on commit c38944e

Please sign in to comment.