Skip to content

Commit 1ffe4d0

Browse files
Copilottorosent
andcommitted
Make DurableClientContext implement AutoCloseable
Co-authored-by: torosent <17064840+torosent@users.noreply.github.com>
1 parent d5853f9 commit 1ffe4d0

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

azurefunctions/src/main/java/com/microsoft/durabletask/azurefunctions/DurableClientContext.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@
2222

2323
/**
2424
* The binding value type for the {@literal @}DurableClientInput parameter.
25+
* <p>
26+
* This class implements {@link AutoCloseable} to ensure proper cleanup of underlying gRPC resources.
27+
* When used with the Azure Functions Java worker, the worker should call {@link #close()} after the
28+
* function invocation completes to release network resources and prevent channel leak warnings.
29+
* </p>
2530
*/
26-
public class DurableClientContext {
31+
public class DurableClientContext implements AutoCloseable {
2732
// These fields are populated via GSON deserialization by the Functions Java worker.
2833
private String rpcBaseUrl;
2934
private String taskHubName;
@@ -148,4 +153,18 @@ private String getInstanceStatusURL(HttpRequestMessage<?> request, String instan
148153

149154
return baseUrl + "/runtime/webhooks/durabletask/instances/" + encodedInstanceId;
150155
}
156+
157+
/**
158+
* Closes the underlying durable task client and releases any associated network resources.
159+
* <p>
160+
* This method should be called when the function invocation is complete to prevent gRPC channel leaks.
161+
* If no client has been created yet (i.e., {@link #getClient()} was never called), this method does nothing.
162+
* </p>
163+
*/
164+
@Override
165+
public void close() {
166+
if (this.client != null) {
167+
this.client.close();
168+
}
169+
}
151170
}

0 commit comments

Comments
 (0)