Close per-query querier in the remote read handler#7672
Conversation
|
Good catch, seems good to me. One minor thing in the description, in tenant-federation merge queryable |
The remote read handler creates a storage.Querier for each sub-query in its own goroutine but never calls Close() on it. It is the only storage.Querier call site in the codebase that does not close the querier, so it does not honor the interface contract. The concrete queriers wired into the read path today all have a Close() that returns nil, so this is not an observed leak in the current code. It is a correctness and consistency fix: any querier that does release resources in Close() (a future implementation, a wrapper, or an upstream Prometheus change) is then released deterministically instead of relying on GC. Defer querier.Close() inside the goroutine so it runs on every path, matching every other querier call site. Add a regression test asserting that each per-query querier is closed. Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com>
e405a42 to
89e69b8
Compare
|
Good point. You are right that I also fixed both CI failures: the test now uses |
What this PR does:
The remote read handler creates a
storage.Querierfor each sub-query but never callsClose(). It is the onlystorage.Queriercall site in Cortex that does not close the querier, so it does not honor the interface contract.The concrete queriers in the current read path have
Close()methods that returnnil, so this is not an observed resource leak today. It is a correctness and consistency fix that ensures future or wrapped queriers which release resources are closed deterministically.This adds
defer querier.Close()immediately after successful creation, covering both success and error paths. A regression test verifies every created querier is closed.Which issue(s) this PR fixes:
No existing issue; found by code inspection.
Checklist
CHANGELOG.mdupdateddocs/configuration/v1-guarantees.mdupdated if this PR introduces experimental flags (n/a, no flags)This change was prepared with AI assistance per the project policy. I reviewed every line, verified the interface and concrete implementations, and validated the tests and linters.