Skip to content

Commit a210b4d

Browse files
authored
Merge pull request #457 from xiaomakuaiz/fix/taskflow-shell-ping-panic
fix(taskflow): avoid shell ping ticker panic
2 parents ac7704d + 7b8f67d commit a210b4d

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

backend/pkg/taskflow/shell.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,25 @@ func (s *Shell) startPing() {
2929
s.mu.Unlock()
3030
return
3131
}
32-
s.pingTicker = time.NewTicker(15 * time.Second)
32+
ticker := time.NewTicker(15 * time.Second)
33+
s.pingTicker = ticker
3334
s.mu.Unlock()
3435

35-
go func() {
36+
go func(ticker *time.Ticker) {
37+
defer func() {
38+
ticker.Stop()
39+
s.mu.Lock()
40+
if s.pingTicker == ticker {
41+
s.pingTicker = nil
42+
}
43+
s.mu.Unlock()
44+
}()
45+
3646
for {
3747
select {
3848
case <-s.ctx.Done():
3949
return
40-
case <-s.pingTicker.C:
50+
case <-ticker.C:
4151
s.mu.Lock()
4252
conn := s.conn
4353
s.mu.Unlock()
@@ -56,7 +66,7 @@ func (s *Shell) startPing() {
5666
cancel()
5767
}
5868
}
59-
}()
69+
}(ticker)
6070
}
6171

6272
func (s *Shell) reconnect(ctx context.Context) error {

0 commit comments

Comments
 (0)