Skip to content

Commit d3bd537

Browse files
Copilottorosent
andcommitted
Add thread safety and idempotent close
Co-authored-by: torosent <17064840+torosent@users.noreply.github.com>
1 parent 026619b commit d3bd537

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public String getTaskHubName() {
4949
*
5050
* @return the Durable Task client object associated with the current function invocation.
5151
*/
52-
public DurableTaskClient getClient() {
52+
public synchronized DurableTaskClient getClient() {
5353
// Return existing client if already initialized
5454
if (this.client != null) {
5555
return this.client;
@@ -162,12 +162,14 @@ private String getInstanceStatusURL(HttpRequestMessage<?> request, String instan
162162
* <p>
163163
* This method should be called when the function invocation is complete to prevent gRPC channel leaks.
164164
* If no client has been created yet (i.e., {@link #getClient()} was never called), this method does nothing.
165+
* This method is idempotent and can be called multiple times safely.
165166
* </p>
166167
*/
167168
@Override
168-
public void close() {
169+
public synchronized void close() {
169170
if (this.client != null) {
170171
this.client.close();
172+
this.client = null;
171173
}
172174
}
173175
}

0 commit comments

Comments
 (0)