blame2020 opened a new issue, #1851:
URL: https://github.com/apache/cassandra-gocql-driver/issues/1851

   I'd like to discuss a potential issue in gocql's query resource management. 
Here's the situation:
   
   1. gocql uses a sync.Pool to manage Query objects:
   ```go
   var queryPool = &sync.Pool{
       New: func() interface{} {
           return &Query{routingInfo: &queryRoutingInfo{}, refCount: 1}
       },
   }
   ```
   
   2. The Query object has two common usage patterns:
   ```go
   // Pattern A: Direct execution
   session.Query("...").Exec()
   
   // Pattern B: With explicit Release
   q := session.Query("...")
   defer q.Release()
   q.Exec()
   ```
   
   3. Looking at Exec():
   ```go
   func (q *Query) Exec() error {
       return q.Iter().Close()
   }
   ```
   
   The question is: Do we really need Release() when using Exec()? The Query 
object is obtained from the pool with an initial refCount of 1, but it's 
unclear whether:
   
   - Exec() properly manages the refCount internally
   - The lack of Release() might cause resource leaks
   - Multiple Release() calls could potentially affect other queries using 
recycled objects from the pool
   
   We've observed the Pattern B in godoc examples, but we're unsure if this is 
actually necessary or potentially problematic. Could you help clarify whether 
Release() is required when using Exec() and the implications of both patterns?
   
   Would appreciate insights on the intended resource management approach here.


-- 
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