Fix resource leak: close staging Rows in execStagingOperation#325
Merged
vikrantpuppala merged 2 commits intodatabricks:mainfrom Feb 24, 2026
Merged
Conversation
execStagingOperation creates a Rows object via rows.NewRows() to read staging operation metadata but never closes it. This leaks the Rows object and its RowScanner resources until GC collects them. Add defer row.Close() to ensure proper cleanup. Related: databricks#275 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR addresses a client-side resource leak in execStagingOperation by ensuring the staging Rows iterator is closed after reading staging metadata, reducing the chance of retained RowScanner/page-iterator resources during concurrent PUT/GET/REMOVE workflows (related to #275).
Changes:
- Add
defer row.Close()after successfully creating stagingRowsinexecStagingOperation.
Comments suppressed due to low confidence (1)
connection.go:594
rows.NewRowscan return a non-nildriver.Rowsalong with a non-nil error (it returnsr, errwhenmakeRowScannerfails). In that case this branch returns without closing the partially-initialized rows, so some client-side resources may still leak. Consider explicitly closingrowwhenerr != nil(if non-nil) before returning, or adjustNewRowsto returnnilon error.
row, err = rows.NewRows(ctx, exStmtResp.OperationHandle, c.client, c.cfg, exStmtResp.DirectResults)
if err != nil {
return dbsqlerrint.NewDriverError(ctx, "error reading row.", err)
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
gopalldb
approved these changes
Feb 23, 2026
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.
Summary
execStagingOperationcreates aRowsobject viarows.NewRows()to read staging operation metadata (presigned URL, headers, local file path) but never callsrow.Close()Rowsobject and itsRowScannerresources until GC collects themdefer row.Close()to ensure proper cleanup after reading the staging metadataNote: the server-side operation is already closed by
ExecContext(lines 122-133), so this is a client-side resource leak rather than a server-side operation leak.Test plan
TestConn_execStagingOperationtests passTestWorkflowExamplee2e test passesgo build ./...compiles cleanlyRelated: #275
🤖 Generated with Claude Code