Skip to content

dataconnect(test): fix resource leaks in DataConnectGrpcRPCsUnitTest.kt#8359

Merged
dconeybe merged 1 commit into
mainfrom
dconeybe/dataconnect/DataConnectGrpcRPCsUnitTestResourceLeakFix
Jun 25, 2026
Merged

dataconnect(test): fix resource leaks in DataConnectGrpcRPCsUnitTest.kt#8359
dconeybe merged 1 commit into
mainfrom
dconeybe/dataconnect/DataConnectGrpcRPCsUnitTestResourceLeakFix

Conversation

@dconeybe

@dconeybe dconeybe commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

This PR addresses resource leak issues in DataConnectGrpcRPCsUnitTest by introducing a thread-safe Cleanups utility class to manage and guarantee the teardown of resources in reverse order of their registration. It refactors the unit tests to utilize Cleanups, ensuring proper cleanup of servers, caches, and gRPC RPC clients.

Highlights

  • Resource Leak Resolution: Refactored DataConnectGrpcRPCsUnitTest to run with Cleanups().use { ... }, registering all server, cache, and client instances for guaranteed teardown, resolving resource leaks.
  • New Cleanups Utility: Introduced a thread-safe Cleanups utility class implementing AutoCloseable that registers synchronous and suspending cleanup tasks, executing them in reverse-registration order, aggregating any thrown exceptions.
  • Enhanced Server Teardown: Updated InProcessDataConnectGrpcStreamingServer to cleanly await termination during its shutdown process.

Changelog

Changelog
  • DataConnectGrpcRPCsUnitTest.kt
    • Refactored tests to use the new Cleanups utility for managing temporary resources (caching, gRPC clients, servers) and cancel pending background jobs during teardown.
    • Updated InProcessDataConnectGrpcStreamingServer.close() to use shutdownNow() and await termination of the gRPC server.
  • Cleanups.kt
    • Added new Cleanups utility class to register and execute synchronous and suspending cleanup functions on close().
    • Implemented exception accumulation using addSuppressed() when multiple cleanups fail.
  • CleanupsUnitTest.kt
    • Added unit tests for the new Cleanups class, verifying registration, ordering, exception handling, and double-close behavior.

@gemini-code-assist

Copy link
Copy Markdown
Contributor
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

@dconeybe

Copy link
Copy Markdown
Contributor Author

/gemini review

@github-actions

Copy link
Copy Markdown
Contributor

📝 PRs merging into main branch

Our main branch should always be in a releasable state. If you are working on a larger change, or if you don't want this change to see the light of the day just yet, consider using a feature branch first, and only merge into the main branch when the code complete and ready to be released.

@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 introduces a new Cleanups utility class to manage synchronous and suspending test cleanup actions, replacing the JUnit CleanupsRule in DataConnectGrpcRPCsUnitTest.kt. It also adds corresponding unit tests for Cleanups and improves the shutdown behavior of the in-process gRPC streaming server. Feedback was provided to replace autoCloseable::class.qualifiedName with autoCloseable.javaClass.name to avoid potential reflection overhead and nullability issues.

@dconeybe dconeybe marked this pull request as ready for review June 25, 2026 07:00
@dconeybe dconeybe merged commit 990367e into main Jun 25, 2026
50 checks passed
@dconeybe dconeybe deleted the dconeybe/dataconnect/DataConnectGrpcRPCsUnitTestResourceLeakFix branch June 25, 2026 13:57
@github-actions github-actions Bot mentioned this pull request Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants