Skip to content

Conversation

@benclive
Copy link
Contributor

@benclive benclive commented Dec 3, 2025

What this PR does / why we need it:
Fix stats propagation by ensuring the query pipeline is closed before building the results.

  • Stats are only aggregated in the pipeline close method, so this must be done before returning results but we were previously doing it in a defer, after the result object was completed.
  • In order to ensure we do always close the pipeline even as this code changes over time, I still deferred it but wrapped it in OnceFunc so it doesn't get called twice. It's not really a problem to call it twice right now but I decided we should avoid this edge case in the future.
@benclive benclive requested a review from a team as a code owner December 3, 2025 14:40
Comment on lines 204 to 207
closePipeline := sync.OnceFunc(func() {
pipeline.Close()
})
defer closePipeline()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny improvement :) (I think this works)

Suggested change
closePipeline := sync.OnceFunc(func() {
pipeline.Close()
})
defer closePipeline()
closePipeline := sync.OnceFunc(pipeline.Close)
defer closePipeline()

Also, maybe we should update the Pipeline interface to note that Close must be safe to call multiple times? I think we can keep the sync.OnceFunc here, but it would be nice to solidify that as part of the contract so we don't have to worry about it every time

@pull-request-size pull-request-size bot added size/S and removed size/XS labels Dec 3, 2025
@benclive benclive enabled auto-merge (squash) December 3, 2025 14:49
@benclive benclive merged commit 99ba51e into main Dec 3, 2025
72 checks passed
@benclive benclive deleted the benclive/ensure-stats-are-calculated branch December 3, 2025 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2 participants