Skip to content

Conversation

@gauravthadani
Copy link

What was changed

Added a project to demonstrate TemporalClient rotation/refresh

Why?

Have a customer needing to refresh client and rotate credentials every 2 hours.
Thought its a worth a sample

Checklist

  1. Closes

  2. How was this tested:

  1. Any docs updates needed?

@gauravthadani gauravthadani marked this pull request as ready for review November 28, 2025 02:29
@gauravthadani gauravthadani requested a review from a team as a code owner November 28, 2025 02:29
var replaceWorkerClient = (TemporalClient newClient) =>
{
worker.Client = newClient;
Console.WriteLine("Client's new handle: {0}", worker.Client.BridgeClientProvider?.BridgeClient?.DangerousGetHandle());
Copy link
Author

@gauravthadani gauravthadani Nov 28, 2025

Choose a reason for hiding this comment

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

okay to log this for the sample?
The idea was to show connection id changing, but don't know if this is the right field.

Copy link
Member

Choose a reason for hiding this comment

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

I would rather not log this, and just say it was replaced. These internals are not considered stable or meant for users.

var replaceWorkerClient = (TemporalClient newClient) =>
{
worker.Client = newClient;
Console.WriteLine("Client's new handle: {0}", worker.Client.BridgeClientProvider?.BridgeClient?.DangerousGetHandle());
Copy link
Member

Choose a reason for hiding this comment

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

I would rather not log this, and just say it was replaced. These internals are not considered stable or meant for users.

Copy link
Member

Choose a reason for hiding this comment

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

Hrmm, I wonder if a single client refresh after some time would be a better demonstration. I have not seen this sample in any other Core-based SDKs, so it is a bit strange to only be in .NET, but not a big deal. However, I do not want to encourage the practice of rotating a client every 10 seconds (many calls are up to a minute long anyways, so rotation may happen a few times before the client is even used). I fear the sample demonstrating this kind of frequent rotation may encourage it.

Copy link
Author

Choose a reason for hiding this comment

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

yes, that is a valid point. I will change to rotating it every 2 hours for the sample.
And leave a comment for making it configurable.

Copy link
Author

Choose a reason for hiding this comment

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

done, let me know if you still prefer the demonstration to be once instead of every 2 hours.
I do understand this is not a Workflow pattern, so happy to sample it elsewhere.

Copy link
Member

Choose a reason for hiding this comment

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

This works for me, but realistically a user may never see the client refresh in the sample. Just want confirmation that's ok with you before merging.

Copy link
Member

@cretz cretz left a comment

Choose a reason for hiding this comment

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

Nothing blocking


try
{
await Task.WhenAll(ClientRefreshAsync(replaceWorkerClient, tokenSource.Token), worker.ExecuteAsync(tokenSource.Token));
Copy link
Member

Choose a reason for hiding this comment

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

Not sure this is worth breaking out into 2 more separate methods vs just inlining the loop here, but not a big deal

Copy link
Member

Choose a reason for hiding this comment

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

This works for me, but realistically a user may never see the client refresh in the sample. Just want confirmation that's ok with you before merging.

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.

3 participants