0

A lot of the Azure client libraries seem to be thread safe and I'm nearly sure I read somewhere that the EventGridClient is too, but I cannot for the life of me find where that was. The MSDN documentation makes no mention either way but I know that there have been cases where the documentation is incorrect.

Can anyone confirm or deny this and provide a source for it, as either my Google-fu is weak today or it simply hasn't been stated anywhere. Cheers.

Steve Pettifer
  • 1,975
  • 1
  • 19
  • 34

1 Answers1

1

As far as I know the rule of thumb in .NET libraries is that instance method are not supposed to be thread safe, while statics are. So if not documented I think this is what we have to consider. Furthermore an instance method could be incidentally thread safe, but since is not documented it could change behavior in future versions, so you should not trust the situation.

Felice Pollano
  • 32,832
  • 9
  • 75
  • 115
  • That's my understanding too, but there are other threads on here regarding the `EventHubClient` (see https://stackoverflow.com/questions/35944887/eventhubclient-sendbatchasync-is-it-thread-safe) which confirm that library is thread safe but the documentation was wrong & got updated shortly after. Sometimes the Azure guys at MS will answer these queries which is what I am hoping for. I thought I read that Azure libraries are (mostly) thread safe but I just can't find where I read that. I'm assuming they're not for now but that requires me to use `lock` in the client factory and I'd rather not. – Steve Pettifer Aug 08 '19 at 07:55
  • 1
    I think if it is not really stated somewhere it is thread safe, we have to consider it is not. I think should not be an issue anyway having a client for thread? – Felice Pollano Aug 08 '19 at 08:04
  • We have a client per EG domain and the factory issues just one per domain (like you would for `HttpClient`). There are multiple threads that can access that factory and I don't think it would cause any problems but I'm erring on the side of caution - if I didn't protect it then I imagine my PR would be rejected and I'd have to justify it as my colleagues are pretty hot at spotting potential problems. I really want to be able to soundly justify my decision and it sounds like in the absence of confirmation of thread safety that I am right to be cautious. – Steve Pettifer Aug 08 '19 at 08:07