Browse Source

Refactor context handling in HandleCount and HandleReq functions

- 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
main
mleku 3 months ago
parent
commit
bc8a557f07
No known key found for this signature in database
  1. 5
      app/handle-count.go
  2. 5
      app/handle-req.go
  3. 2
      pkg/version/version

5
app/handle-count.go

@ -43,8 +43,9 @@ func (l *Listener) HandleCount(msg []byte) (err error) { @@ -43,8 +43,9 @@ 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

5
app/handle-req.go

@ -86,9 +86,10 @@ func (l *Listener) HandleReq(msg []byte) (err error) { @@ -86,9 +86,10 @@ func (l *Listener) HandleReq(msg []byte) (err error) {
// user has read access or better, continue
}
var events event.S
// Create a single context for all filter queries, tied to the connection context, to prevent leaks and support timely cancellation
// Create a single context for all filter queries, isolated from the connection context
// to prevent query timeouts from affecting the long-lived websocket connection
queryCtx, queryCancel := context.WithTimeout(
l.ctx, 30*time.Second,
context.Background(), 30*time.Second,
)
defer queryCancel()

2
pkg/version/version

@ -1 +1 @@ @@ -1 +1 @@
v0.17.16
v0.17.17
Loading…
Cancel
Save