Skip to content

Add DurableTaskGrpcClientFactory#256

Merged
sophiatev merged 13 commits intomainfrom
stevosyan/add-grpc-client-factory
Jan 30, 2026
Merged

Add DurableTaskGrpcClientFactory#256
sophiatev merged 13 commits intomainfrom
stevosyan/add-grpc-client-factory

Conversation

@sophiatev
Copy link
Contributor

Issue describing the changes in this PR

resolves #254

Currently, the DurableClientContext instantiates but never calls close on its DurableTaskGrpcClient instance. This can lead to the errors referenced in #254. To remedy this, this PR instead changes the DurableClientContext to use the DurableTaskGrpcClientFactory which essentially creates static singletons of each gRPC client for each port throughout the application's lifetime. This should remove any issues with clients being recreated for the same port without properly being closed.

Pull request checklist

  • My changes do not require documentation changes
    • Otherwise: Documentation issue linked to PR
  • My changes are added to the CHANGELOG.md
  • I have added all required tests (Unit tests, E2E tests)

@sophiatev sophiatev requested a review from a team as a code owner January 28, 2026 07:22
Copilot AI review requested due to automatic review settings January 28, 2026 07:22
@sophiatev
Copy link
Contributor Author

@copilot Please add unit tests to this PR that validate that calling DurableTaskGrpcClientFactory.getClient returns the same client instance for the same port, and that multiple clients can successfully be created for different ports.

Copy link
Contributor

Copilot AI commented Jan 28, 2026

@sophiatev I've opened a new pull request, #257, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses issue #254 by introducing a DurableTaskGrpcClientFactory that creates singleton gRPC clients per port, preventing repeated warnings about improperly closed gRPC channels. The previous implementation created a new client for each function invocation without properly closing them.

Changes:

  • Added DurableTaskGrpcClientFactory to manage singleton client instances per port
  • Added a new package-private constructor to DurableTaskGrpcClient that accepts only a port parameter
  • Updated DurableClientContext to use the factory instead of directly instantiating clients via the builder
  • Bumped version numbers across modules to 1.6.2

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
client/src/main/java/com/microsoft/durabletask/DurableTaskGrpcClientFactory.java New factory class that maintains singleton gRPC clients per port using ConcurrentHashMap
client/src/main/java/com/microsoft/durabletask/DurableTaskGrpcClient.java Added new constructor accepting port parameter for use by the factory
azurefunctions/src/main/java/com/microsoft/durabletask/azurefunctions/DurableClientContext.java Refactored to use factory instead of builder, simplified client caching logic
client/build.gradle Version bump to 1.6.2
azuremanaged/build.gradle Version bump to 1.6.2
azurefunctions/build.gradle Version bump to 1.6.2
CHANGELOG.md Added entry for v1.6.2 referencing gRPC channel shutdown fix

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 9 to 15
public final class DurableTaskGrpcClientFactory {
private static final ConcurrentMap<Integer, DurableTaskGrpcClient> portToClientMap = new ConcurrentHashMap<>();

public static DurableTaskClient getClient(int port) {
return portToClientMap.computeIfAbsent(port, DurableTaskGrpcClient::new);
}
} No newline at end of file
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

The factory creates singleton clients that are never closed during the application lifecycle. While this is intentional to prevent the channel shutdown warnings mentioned in issue #254, it means gRPC channels will remain open until the JVM exits. Consider adding a method to explicitly close all cached clients for scenarios where the application needs to shut down gracefully, such as when running in tests or when the Azure Functions host is shutting down. This would allow proper resource cleanup while maintaining the singleton pattern during normal operation.

Copilot uses AI. Check for mistakes.
Sophia Tevosyan and others added 3 commits January 27, 2026 23:29
…nctions/DurableClientContext.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sophia Tevosyan and others added 6 commits January 27, 2026 23:37
* Initial plan

* Add unit tests for DurableTaskGrpcClientFactory and fix compilation error

Co-authored-by: sophiatev <38052607+sophiatev@users.noreply.github.com>

* Remove changes to DurableTaskGrpcClient.java and proto file, keep only test file

Co-authored-by: sophiatev <38052607+sophiatev@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: sophiatev <38052607+sophiatev@users.noreply.github.com>
@sophiatev sophiatev merged commit 7341810 into main Jan 30, 2026
8 checks passed
@sophiatev sophiatev deleted the stevosyan/add-grpc-client-factory branch January 30, 2026 17:53
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.

DurableClientContext gRPC channels are never closed after function invocation

3 participants