Is Azure IoT Hub's DeviceClient thread safe or not?

Is Azure IoT Hub's DeviceClient thread safe or not?



I have a client whose device app gets hung up occasionally, and they haven't been able to figure out why. The device app is a long-running Windows service using the .NET Azure SDK. I've reviewed the code base and have noticed that they have two separate threads each running a loop, with one sending D2C messages, and the other receiving C2D messages, both using the same instance of DeviceClient. Sounds like a potential race condition to me. That makes me wonder if the .NET DeviceClient class is thread safe. Anyone else run into this?



This old (2016) post mentions DeviceClient not being thread-safe, but the current DeviceClient documentation doesn't mention anything about thread safety.



FWIW, they have just over 4000 devices sending around 25MM messages in total per week, and are using MQTT.
Thanks!





Hi Vince, I can't reproduce your issue by setting up a timer to call deviceClient.SendAsync() and while deviceClient.ReceiveAsync() is running in another thread, the period of the timer is 1ms. So have you tried the suggestion using autoResetEvent to see if it helps? If you can share the code sample to reproduce this issue I can do a further investigation.
– Rita Han - MSFT
Aug 27 at 6:21


deviceClient.SendAsync()


deviceClient.ReceiveAsync()


autoResetEvent









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)