Close datastore iterators to release underlying rows and Firestore resources on decode errors - #7226
Open
vanshika2720 wants to merge 1 commit into
Open
Conversation
…sources on decode errors Signed-off-by: Vanshika <pahalvanshikaa@gmail.com>
vanshika2720
requested review from
armistcxy,
ffjlabo and
t-kikuc
and
a lite review from Copilot
August 23, 2026 11:35
✅ Deploy Preview for pipecd-site ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves PipeCD’s datastore layer by adding explicit iterator cleanup, ensuring underlying MySQL sql.Rows and Firestore DocumentIterator resources are released even when iteration exits early due to decode/scan errors. This aligns iterator lifecycle management with how PipeCD continuously polls datastore lists and reduces risk of connection/resource exhaustion under repeated failures.
Changes:
- Extend
datastore.IteratorwithClose() errorand implement it for MySQL and Firestore iterators. - Ensure datastore store
List()implementations and integration test iteration helpersdefer it.Close()after successfulFind(). - Update gomock iterator mock and unit tests to assert
Close()is invoked on both success and error paths.
Reviewed changes
Copilot reviewed 27 out of 28 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
pkg/datastore/datastore.go |
Adds Close() error to the Iterator interface with lifecycle guidance. |
pkg/datastore/mysql/iterator.go |
Implements Close() by closing underlying sql.Rows. |
pkg/datastore/firestore/iterator.go |
Implements Close() by stopping the underlying Firestore DocumentIterator. |
pkg/datastore/mock.go |
Regenerates/updates gomock to include Iterator.Close(). |
pkg/datastore/projectstore.go |
Defers iterator close in List() to ensure cleanup. |
pkg/datastore/pipedstore.go |
Defers iterator close in List(). |
pkg/datastore/eventstore.go |
Defers iterator close in List(). |
pkg/datastore/deploymenttracestore.go |
Defers iterator close in List(). |
pkg/datastore/deploymentstore.go |
Defers iterator close in List(). |
pkg/datastore/deploymentchainstore.go |
Defers iterator close in List(). |
pkg/datastore/commandstore.go |
Defers iterator close in List(). |
pkg/datastore/applicationstore.go |
Defers iterator close in List(). |
pkg/datastore/apikey.go |
Defers iterator close in List(). |
pkg/datastore/projectstore_test.go |
Updates expectations to assert Close() is called. |
pkg/datastore/pipedstore_test.go |
Updates expectations to assert Close() is called. |
pkg/datastore/deploymentstore_test.go |
Updates expectations to assert Close() is called. |
pkg/datastore/commandstore_test.go |
Updates expectations to assert Close() is called. |
pkg/datastore/applicationstore_test.go |
Updates expectations to assert Close() is called. |
pkg/datastore/apikey_test.go |
Updates expectations to assert Close() is called. |
test/integration/datastore/mysql/project_test.go |
Defers iterator close in test helper iteration. |
test/integration/datastore/mysql/piped_test.go |
Defers iterator close in test helper iteration. |
test/integration/datastore/mysql/event_test.go |
Defers iterator close in test helper iteration. |
test/integration/datastore/mysql/deploymentchain_test.go |
Defers iterator close in test helper iteration. |
test/integration/datastore/mysql/deployment_test.go |
Defers iterator close in test helper iteration. |
test/integration/datastore/mysql/command_test.go |
Defers iterator close in test helper iteration. |
test/integration/datastore/mysql/application_test.go |
Defers iterator close in test helper iteration. |
test/integration/datastore/mysql/apikey_test.go |
Defers iterator close in test helper iteration. |
test/integration/datastore/firestore/firestore_test.go |
Defers iterator close in test helper iteration. |
Files not reviewed (1)
- pkg/datastore/mock.go: Generated file
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does:
Adds explicit resource cleanup to
datastore.Iteratorso underlying MySQL and Firestore iterators are closed when datastore iteration completes or exits early due to an error. AllList()callers now defer iterator cleanup, and tests verify thatClose()is called on both successful and error paths.Why we need it:
Previously,
datastore.Iteratorhad noClose()method, so an early return caused by a decode/scan error could leave the underlyingsql.Rowsor FirestoreDocumentIteratoropen. Repeated failures could accumulate unreleased database resources and potentially exhaust available connections.Which issue(s) this PR fixes:
Fixes #7219
Does this PR introduce a user-facing change?: