ordercloud-api / ordercloud-dotnet-sdk

The official .NET SDK for the OrderCloud eCommerce platform
MIT License
15 stars 14 forks source link

Put an async lock around updating OrderCloudClient.TokenResponse #21

Open tmenier opened 6 years ago

tmenier commented 6 years ago

Authenticate() might not be threadsafe as is, or at the very least multiple threads could be authenticating and the same time and overwriting each other's results, which is not necessarily harmful but is a bit of a waste.

Possibly use a SemaphorSlim.

tmenier commented 2 years ago

The main thread-safety concern was in the logic that automatically authenticates and refreshes tokens when necessary. This was updated in #97 to use async locking, which should cover the majority of auth scenarios. Per the docs, "there should be very few use cases where [manually authenticating] is necessary", so although technically this issue isn't fixed, the cases where it could come up are far fewer.