Skip to content

fix(spanner): missing callback parameter in close#8127

Open
alkatrivedi wants to merge 2 commits intomainfrom
fix-close
Open

fix(spanner): missing callback parameter in close#8127
alkatrivedi wants to merge 2 commits intomainfrom
fix-close

Conversation

@alkatrivedi
Copy link
Copy Markdown
Contributor

fixes: #8106

@alkatrivedi alkatrivedi requested a review from a team as a code owner April 28, 2026 04:32
@product-auto-label product-auto-label Bot added the api: spanner Issues related to the Spanner API. label Apr 28, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the Spanner.close() method to support an optional callback and adds unit tests to verify the cleanup of cached clients. A review comment suggests improving the error handling in the close method to ensure that errors are still logged to the console if no callback is provided, preventing silent failures during cleanup.

Comment thread handwritten/spanner/src/index.ts Outdated
@alkatrivedi
Copy link
Copy Markdown
Contributor Author

/gemini

Comment thread handwritten/spanner/src/index.ts Outdated

/** Closes this Spanner client and cleans up all resources used by it. */
close(): void {
close(callback?: (err: Error | null) => void): void {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we should return promise as well for customers who would want to await rather than using callback ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the methods is included in promisifyAll here , hence, we need not to explicitly return the promise here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

since promisifyAll will promisify the method only during runtime, hence it the typescript customers wont be able to await on it

to fix the gap, I have added promise return type as well

Comment thread handwritten/spanner/test/index.ts Outdated
});

describe('close', () => {
it('should close all cached clients', done => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should use async/await for tests instead of "done".

With "done" tests get stuck when it fails.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

// Wait for all clients to close, then do cleanup
Promise.all(promises)
.then(() => cleanup())
.then(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This needs to be conditional. If async/await is used instead of callback then we need to return the promise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: spanner Issues related to the Spanner API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

spanner: Spanner.close() never resolves when called as a Promise

2 participants