Refactor context handling in HandleCount and HandleReq functions
Some checks failed
Go / build (push) Has been cancelled
Go / release (push) Has been cancelled

- Updated context creation in HandleCount and HandleReq to use context.Background() instead of the connection context, isolating timeouts to prevent affecting long-lived websocket connections.
- Improved comments for clarity on the purpose of the context changes.
- bump version to v0.17.17
This commit is contained in:
2025-10-24 16:55:15 +01:00
parent da1119db7c
commit bc8a557f07
3 changed files with 9 additions and 7 deletions

View File

@@ -25,7 +25,7 @@ func (l *Listener) HandleCount(msg []byte) (err error) {
if _, err = env.Unmarshal(msg); chk.E(err) {
return normalize.Error.Errorf(err.Error())
}
log.D.C(func() string { return fmt.Sprintf("COUNT sub=%s filters=%d", env.Subscription, len(env.Filters)) })
log.D.C(func() string { return fmt.Sprintf("COUNT sub=%s filters=%d", env.Subscription, len(env.Filters)) })
// If ACL is active, send a challenge (same as REQ path)
if acl.Registry.Active.Load() != "none" {
@@ -43,14 +43,15 @@ func (l *Listener) HandleCount(msg []byte) (err error) {
// allowed to read
}
// Use a bounded context for counting
ctx, cancel := context.WithTimeout(l.ctx, 30*time.Second)
// Use a bounded context for counting, isolated from the connection context
// to prevent count timeouts from affecting the long-lived websocket connection
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
// Aggregate count across all provided filters
var total int
var approx bool // database returns false per implementation
for _, f := range env.Filters {
for _, f := range env.Filters {
if f == nil {
continue
}