0x-infinity opened a new issue, #992:
URL: https://github.com/apache/incubator-seata-go/issues/992
### 讨论详情
### Description
Multiple background goroutines in the project do not listen to `ctx.Done()`,
preventing graceful shutdown.
**Location 1**: `pkg/datasource/sql/datasource/base/meta_cache.go:89-159`
```go
func (c *BaseTableMetaCache) refresh(ctx context.Context) {
ticker := time.NewTicker(time.Duration(1 * time.Minute))
defer ticker.Stop()
for range ticker.C { // not listening to ctx.Done()
f()
}
}
func (c *BaseTableMetaCache) scanExpire(ctx context.Context) {
ticker := time.NewTicker(c.expireDuration)
for range ticker.C { // not listening to ctx.Done()
// ...
}
}
```
**Location 2**: `pkg/datasource/sql/async_worker.go:125-139`
```go
func (aw *AsyncWorker) run() {
ticker := time.NewTicker(aw.conf.BufferCleanInterval)
for { // infinite loop with no exit condition
select {
case phaseCtx := <-aw.commitQueue:
// ...
case <-ticker.C:
// ...
// missing case <-ctx.Done(): return
}
}
}
```
### Why Need Improve
1. After the `Destroy()` method calls `cancel()`, goroutines cannot exit
2. Causes goroutine leaks, preventing memory release
3. May lose unprocessed transactions in commitQueue when the application
shuts down
4. If the application needs to initialize/destroy cache multiple times, it
will result in numerous zombie goroutines
### 📚 相关背景
_No response_
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]