Skip to content

Commit

Permalink
enh: wait for all action finish before close
Browse files Browse the repository at this point in the history
  • Loading branch information
huskar-t committed Nov 22, 2024
1 parent fc6687f commit 51d0f53
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 3 additions & 2 deletions controller/ws/tmq/tmq.go
Original file line number Diff line number Diff line change
Expand Up @@ -1235,10 +1235,11 @@ func (t *TMQ) Close(logger *logrus.Entry) {
}()
select {
case <-ctx.Done():
logger.Error("wait for all goroutines to exit timeout")
logger.Warn("wait stop over 1 minute")
<-done
case <-done:
logger.Debug("all goroutines exit")
}
logger.Debug("wait stop done")
isDebug := log.IsDebug()

defer func() {
Expand Down
6 changes: 5 additions & 1 deletion controller/ws/ws/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,20 @@ func (h *messageHandler) stop() {
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()

waitCh := make(chan struct{}, 1)
waitCh := make(chan struct{})
go func() {
h.wait.Wait()
close(waitCh)
}()

select {
case <-ctx.Done():
h.logger.Warn("wait stop over 1 minute")
<-waitCh
break
case <-waitCh:
}
h.logger.Debugf("wait stop done")
// clean query result and stmt
h.queryResults.FreeAll(h.logger)
h.stmts.FreeAll(h.logger)
Expand Down

0 comments on commit 51d0f53

Please sign in to comment.