Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query Resource Management in gocql: Is Release() Necessary with Exec()? #1851

Open
blame2020 opened this issue Dec 25, 2024 · 0 comments
Open

Comments

@blame2020
Copy link

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:
var queryPool = &sync.Pool{
    New: func() interface{} {
        return &Query{routingInfo: &queryRoutingInfo{}, refCount: 1}
    },
}
  1. The Query object has two common usage patterns:
// Pattern A: Direct execution
session.Query("...").Exec()

// Pattern B: With explicit Release
q := session.Query("...")
defer q.Release()
q.Exec()
  1. Looking at Exec():
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant