Skip to content

fix(tests): prevent resource leaks by using context.WithoutCancel - #3849

Merged
Yuan325 merged 2 commits into
googleapis:mainfrom
emagda97:fix/teardown-context-leaks
Aug 21, 2026
Merged

Yuan325 merged 2 commits into
googleapis:mainfrom
emagda97:fix/teardown-context-leaks

Conversation

@emagda97

@emagda97 emagda97 commented Aug 19, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Previously, test cleanups and teardown routines (such as dropping temporary tables, instances, or roles) were bound to the parent test context.Context. If a test suite exceeded its timeout, panicked, or failed early, the context was canceled, preventing the teardown loop from firing successfully and leaving abandoned resources on our GCP infrastructure.

Solution

Wrapped cleanup invocations with context.WithoutCancel(ctx) across affected data sources (Bigtable, Spanner,
Dataplex, BigQuery, etc.).

PR Checklist

  • [✅] Make sure you reviewed
    CONTRIBUTING.md
  • [✅] Make sure to open an issue as a
    bug/issue
    before writing your code! That way we can discuss the change, evaluate
    designs, and agree on the general idea
  • [✅] Ensure you have manually reviewed the entire diff before requesting a
    review
  • [✅] Ensure the tests and linter pass
  • [✅] Code coverage does not decrease (if any source code was changed)
  • [✅] Appropriate docs were updated (if necessary)
  • [✅] Make sure to add ! if this involve a breaking change

🛠️ Fixes #3707 (partially)

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

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.

Code Review

This pull request updates various integration tests to use context.WithoutCancel(ctx) during teardown and cleanup operations, ensuring resources are properly cleaned up even if the parent context is canceled. Feedback on the changes highlights that this was incorrectly applied to the setup phase of setupPostgresPublicationTable in tests/tool.go, where respecting context cancelation is still desired to fail fast.

Comment thread tests/tool.go Resolved
@emagda97
emagda97 force-pushed the fix/teardown-context-leaks branch 2 times, most recently from 15b5b72 to e868183 Compare August 19, 2026 22:52
@emagda97 emagda97 changed the title fix(tests): prevent resource leaks by using context.WithoutCancel in teardowns fix(tests): prevent resource leaks by using context.WithoutCancel Aug 19, 2026
@emagda97
emagda97 requested review from Yuan325 and anubhav756 August 20, 2026 18:44
@emagda97
emagda97 marked this pull request as ready for review August 20, 2026 18:44
@emagda97
emagda97 requested review from a team as code owners August 20, 2026 18:44
@emagda97
emagda97 force-pushed the fix/teardown-context-leaks branch from e868183 to 4dccfe8 Compare August 20, 2026 20:45
Previously, test cleanups and teardown routines (such as dropping temporary tables, instances, or roles) were bound to the parent test context.Context. If a test suite exceeded its timeout, panicked, or failed early, the context was canceled, preventing the teardown loop from firing successfully and leaving abandoned resources on our GCP infrastructure.

Wrapped cleanup invocations with context.WithoutCancel(ctx) across affected data sources (Bigtable, Spanner, Dataplex, BigQuery, etc.). This guarantees that resource reclamation pipelines run to completion independent of whether standard probes triggered premature expiration.
@emagda97
emagda97 force-pushed the fix/teardown-context-leaks branch from 4dccfe8 to 3566a44 Compare August 20, 2026 20:46
@Yuan325
Yuan325 enabled auto-merge (squash) August 21, 2026 03:04
@Yuan325
Yuan325 merged commit f97a4f9 into googleapis:main Aug 21, 2026
20 checks passed
Yuan325 added a commit that referenced this pull request Aug 27, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.10.0](v1.9.0...v1.10.0)
(2026-08-27)


### Features

* **falkordb:** Add FalkorDB source and tools
([#3692](#3692))
([a94702c](a94702c))
* **firestore-mongodb:** Add firestore-execute-mql and firestore-get-…
([#3826](#3826))
([4a85d75](4a85d75))
* **mcp:** Add Secure Parameters support as Toolbox experimental
extension
([#3394](#3394))
([9750d2d](9750d2d))
* **server/mcp:** Support com.google.cloud/toolbox.v1 extension in
v20260728
([#3801](#3801))
([f4f7da6](f4f7da6))
* **skill:** Add fix-failing-tests skill for mcp-toolbox
([#3821](#3821))
([168e69c](168e69c))
* **sources:** Support native read-only mode and dynamic tool
annotations
([#3872](#3872))
([c257022](c257022)),
refs [#3615](#3615)
[#3816](#3816)
[#3618](#3618)
[#3851](#3851)
[#3619](#3619)
[#3617](#3617)
* **tool/mongodb:** Allow collection to be specified at runtime
([#3715](#3715))
([7626eaf](7626eaf))


### Bug Fixes

* **cloud-storage:** Resolve symlinks when enforcing local path
boundaries
([#3810](#3810))
([c2ada64](c2ada64))
* **config:** Compare env var offsets in rune space when skipping
comments
([#3856](#3856))
([2e76934](2e76934))
* Merge prebuilt tools when reloading custom config
([#3864](#3864))
([5a6d865](5a6d865))
* Normalize postgres UUIDs to strings
([#3806](#3806))
([3b02f1d](3b02f1d))
* **postgres:** Filter background processes in
postgres-list-active-queries
([#3885](#3885))
([3d9e62a](3d9e62a))
* **test/alloydbainl:** Use explicit SQL alias prompts to stabilize AI…
([#3877](#3877))
([50e45ed](50e45ed))
* **tests:** Prevent resource leaks by using context.WithoutCancel
([#3849](#3849))
([f97a4f9](f97a4f9))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
Co-authored-by: Yuan Teoh <[email protected]>
github-actions Bot pushed a commit that referenced this pull request Aug 27, 2026
🤖 I have created a release *beep* *boop*
---

##
[1.10.0](v1.9.0...v1.10.0)
(2026-08-27)

### Features

* **falkordb:** Add FalkorDB source and tools
([#3692](#3692))
([a94702c](a94702c))
* **firestore-mongodb:** Add firestore-execute-mql and firestore-get-…
([#3826](#3826))
([4a85d75](4a85d75))
* **mcp:** Add Secure Parameters support as Toolbox experimental
extension
([#3394](#3394))
([9750d2d](9750d2d))
* **server/mcp:** Support com.google.cloud/toolbox.v1 extension in
v20260728
([#3801](#3801))
([f4f7da6](f4f7da6))
* **skill:** Add fix-failing-tests skill for mcp-toolbox
([#3821](#3821))
([168e69c](168e69c))
* **sources:** Support native read-only mode and dynamic tool
annotations
([#3872](#3872))
([c257022](c257022)),
refs [#3615](#3615)
[#3816](#3816)
[#3618](#3618)
[#3851](#3851)
[#3619](#3619)
[#3617](#3617)
* **tool/mongodb:** Allow collection to be specified at runtime
([#3715](#3715))
([7626eaf](7626eaf))

### Bug Fixes

* **cloud-storage:** Resolve symlinks when enforcing local path
boundaries
([#3810](#3810))
([c2ada64](c2ada64))
* **config:** Compare env var offsets in rune space when skipping
comments
([#3856](#3856))
([2e76934](2e76934))
* Merge prebuilt tools when reloading custom config
([#3864](#3864))
([5a6d865](5a6d865))
* Normalize postgres UUIDs to strings
([#3806](#3806))
([3b02f1d](3b02f1d))
* **postgres:** Filter background processes in
postgres-list-active-queries
([#3885](#3885))
([3d9e62a](3d9e62a))
* **test/alloydbainl:** Use explicit SQL alias prompts to stabilize AI…
([#3877](#3877))
([50e45ed](50e45ed))
* **tests:** Prevent resource leaks by using context.WithoutCancel
([#3849](#3849))
([f97a4f9](f97a4f9))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
Co-authored-by: Yuan Teoh <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Toolbox Integration Test Cleanup

2 participants