0x-infinity opened a new issue, #991:
URL: https://github.com/apache/incubator-seata-go/issues/991

   ### 讨论详情
   
   ### Description
   The project has multiple database connection leak issues, primarily in the 
following locations:
   
   **Location 1**: `pkg/datasource/sql/datasource/base/meta_cache.go:105-112`
   ```go
   func (c *BaseTableMetaCache) refresh(ctx context.Context) {
       f := func() {
           // ...
           conn, err := c.db.Conn(ctx)
           if err != nil {
               return  // conn not closed
           }
           v, err := c.trigger.LoadAll(ctx, c.cfg.DBName, conn, tables...)
           if err != nil {
               return  // conn not closed
           }
           // conn is never closed throughout the entire function
       }
   }
   ```
   
   **Location 2**: `pkg/datasource/sql/async_worker.go:188-193`
   ```go
   func (aw *AsyncWorker) dealWithGroupedContexts(resID string, phaseCtxs 
[]phaseTwoContext) {
       conn, err := res.db.Conn(context.Background())
       if err != nil {
           for i := range phaseCtxs {
               aw.commitQueue <- phaseCtxs[i]
           }
           // missing return, continuing execution will cause defer 
conn.Close() to panic when conn is nil
       }
       defer conn.Close()
   }
   ```
   
   **Location 3**: `pkg/datasource/sql/db.go:127-139`
   ```go
   func (db *DBResource) init() {
       ctx := context.Background()
       conn, err := db.connector.Connect(ctx)  // create connection
       if err != nil {
           log.Errorf("connect: %v", err)
       }
       version, err := selectDBVersion(ctx, conn)
       // ... conn is never closed
   }
   ```
   
   ### Why Need Improve
   1. Database connections are limited resources; leaks will lead to connection 
pool exhaustion
   2. `refresh()` is a periodic task (executes every minute); prolonged 
operation will cause severe resource issues
   3. `init()` is called when each data source is instantiated, leaking one 
connection each time
   4. In high-concurrency scenarios, connection leaks accumulate rapidly, 
ultimately causing service unavailability
   
   ### 📚 相关背景
   
   _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]

Reply via email to