-
Notifications
You must be signed in to change notification settings - Fork 235
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
fix(iot-dev): fix thread-leak issue with IotHubReconnectTask #1567
Conversation
/azp run |
Azure Pipelines successfully started running 4 pipeline(s). |
device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/DeviceIO.java
Show resolved
Hide resolved
device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/DeviceIO.java
Outdated
Show resolved
Hide resolved
I double checked that we didn't have any threads leaking here, and it seems your fix works in that regard. That said, when I go through a basic connection loss event, I see that the SDK behaves like this:
I'd rather we didn't stop the reconnect thread here* just to create a new thread pool here**. If the reconnect task is already running, then we don't need to do anything to it after we regain connectivity. Something like: private void startWorkerThreads()
{
stopSendAndReceiveThreads();
this.sendTaskScheduler = Executors.newScheduledThreadPool(1);
this.receiveTaskScheduler = Executors.newScheduledThreadPool(1);
this.sendTaskScheduler.scheduleWithFixedDelay(this.sendTask, 0,
sendPeriodInMilliseconds, TimeUnit.MILLISECONDS);
this.receiveTaskScheduler.scheduleWithFixedDelay(this.receiveTask, 0,
receivePeriodInMilliseconds, TimeUnit.MILLISECONDS);
// This is only set to null if the client as a whole has been closed. This thread pool stays active through disconnected_retrying
if (this.reconnectTaskScheduler == null)
{
this.reconnectTaskScheduler = Executors.newScheduledThreadPool(1);
this.reconnectTaskScheduler.scheduleWithFixedDelay(this.reconnectTask, 0,
receivePeriodInMilliseconds, TimeUnit.MILLISECONDS);
}
} |
Yes, this seems more reasonable! |
/azp run |
Azure Pipelines successfully started running 4 pipeline(s). |
For #1563:
Before this fix, the reconnect thread was not cleared appropriately. As a result, an instance of
IotHubReconnectTask
would be created per connection-status change from "DISCONNECTED_RETRYING" to "CONNECTED", while the previous thread was still waiting until the connection turned into "DISCONNECTED" eventually.Thread dump before this fix:
Thread dump after this fix: