Skip to content
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] Provisioning Device Client throws "Open called on an already open connection" with wrong logic? #1772

Closed
in-fke opened this issue Dec 13, 2023 · 2 comments

Comments

@in-fke
Copy link

in-fke commented Dec 13, 2023

Context

  • OS and version used: Windows 10
  • Java runtime used: Java 11
  • SDK version used: 2.1.2

Description of the issue

Implementing reconnect mechanism when network was offline, invoking ProvisioningDeviceClient.registerDevice() throws ProvisioningDeviceConnectionException with message "Open called on an already open connection".

Code sample exhibiting the issue

see https://github.com/Azure/azure-iot-sdk-java/blob/main/provisioning/provisioning-device-client/src/main/java/com/microsoft/azure/sdk/iot/provisioning/device/internal/contract/mqtt/ContractAPIMqtt.java#L161
Code states:

        if (this.mqttConnection != null && !this.mqttConnection.isMqttConnected())
        {
            throw new ProvisioningDeviceConnectionException("Open called on an already open connection");
        }

should it not state instead?

        if (this.mqttConnection != null && this.mqttConnection.isMqttConnected())
        {
            throw new ProvisioningDeviceConnectionException("Open called on an already open connection");
        }

Also, closing the client does not null the field mqttConnection (which would help with the above logic), so apparently, the only solution is to throw away the client when we know that there was a disconnect?

https://github.com/Azure/azure-iot-sdk-java/blob/main/provisioning/provisioning-device-client/src/main/java/com/microsoft/azure/sdk/iot/provisioning/device/internal/contract/mqtt/ContractAPIMqtt.java#L208

So apparently, ProvisioningDeviceClient is not intended to be re-used for multiple invocations of registerDevice at all, if it seems?

Console log of the issue

n/a

@in-fke in-fke added the bug label Dec 13, 2023
@timtay-microsoft
Copy link
Member

This does look a bit off. We'll take a deeper look when we get a chance. Thanks for catching this!

@timtay-microsoft
Copy link
Member

This has been fixed as of provisioning device client version 2.1.3, so I'll close this thread

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants