-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug Report] RegisterTask thread not finalized if ProvisioningDeviceClient is closed too fast #1736
Comments
…t cleanup all threads If the provisioning task was interrupted by the user closing the client, it needs to shutdown its executor service that runs the RegisterTask This fix addresses #1736
Thanks for catching this. It looks like the thread running the ProvisioningTask (which owns the thread that runs the RegisterTask thread that is leaking) isn't catching interrupted exceptions and cleaning up appropriately. #1741 should fix this issue for you |
@timtay-microsoft, thank you very much! |
The fix has been checked in, and we'll try to get a release out soon |
Version 2.1.2 has been published with this fix, some I'll close this thread |
Context
Description of the issue
To contextualize a bit, I have a service running under my device that implements Azure DPS and allows clients to provision their devices using symmetric keys. I have a task that periodically retries the provisioning in case of failure, however, the user can start/cancel the provisioning process and the retry task (before the device is assigned in the cloud) at any time. Provisioning is done using the async
ProvisioningDeviceClient.registerDevice()
method.However, during tests with some failure cases, after killing the provisioning process at some times I would have a
azure-iot-sdk-RegisterTask
named thread still lingering around in aWAITING
state and it never finishes.After some debugging, I believe that this happens when the provisioning process is asked to be stopped (thus
ProvisioningDeviceClient.close()
is called) too quickly after callingProvisioningDeviceClient.registerDevice()
.It appears to me that, if
close()
is called before the task fromRegisterTask
is done, the thread will never finish.I was able to create a scenario to reproduce this problem using a sample code from the SDK with some modifications to use the async method instead (attached below).
If you take a thread dump after the
Press any key to exit...
message appears in the console, there should be aazure-iot-sdk-RegisterTask
thread running.If you switch the commented lines and wait a longer time, all DPS threads should be cleared. (During some tests I saw a
ProvisioningTask
thread still running, but that one was finalized after some seconds).Code sample exhibiting the issue
Console log of the issue
Log of the code variant that presents the issue (Sleeping for 500ms)
Thread dump of this run
Log of the code variant issue-free (Sleeping for 5 secs)
Thread dump of this run
The text was updated successfully, but these errors were encountered: