azure-sdk-for-go icon indicating copy to clipboard operation
azure-sdk-for-go copied to clipboard

Should I make the creation of a new client a singleton?

Open veerun14 opened this issue 2 years ago • 2 comments

PR https://github.com/Azure/azure-sdk-for-go/pull/17742 adds support for AAD authentication by use of azcore.TokenCredential.

My question is should the client created this way be made a singleton across your app? The Performance guide in the documentation here suggests use of a singleton, but that is for .Net SDK and not for Go

What happens when the token is expired? Should I add a retry?

veerun14 avatar Aug 05 '22 00:08 veerun14

should the client created this way be made a singleton across your app?

Our clients for HTTP services (including AAD) share a single http.Client by default. If you aren't replacing that http.Client, I doubt there's much to be gained by using a singleton azcosmos.Client.

What happens when the token is expired? Should I add a retry?

The Cosmos client and azidentity credential handle retries and token refreshing internally. When a Cosmos client method returns an authentication error, the error is either not retriable (think "wrong password") or the client has exhausted its allowed retries (think "network down"). So, you probably don't want to simply call the method again, but it may be possible for your application to recover. The azidentity troubleshooting guide has more information about specific authentication errors.

chlowell avatar Aug 05 '22 16:08 chlowell

Hi, we're sending this friendly reminder because we haven't heard back from you in a while. We need more information about this issue to help address it. Please be sure to give us your input within the next 7 days. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!

msftbot[bot] avatar Aug 12 '22 20:08 msftbot[bot]