Azure-iot-sdk-csharp: Multipe connections detected for device in MQTT

Created on 9 Jul 2018  路  11Comments  路  Source: Azure/azure-iot-sdk-csharp

  • OS, version, SKU and CPU architecture used:
    Windows 10, Docker 18.03.1-ce-win65 linux container mode
  • SDK version used:
    1.17.0

Description of the issue:


I am trying to run an edge module in local machine (without docker). The steps are as follows

  1. Start edgeHub container with all credential, network and volume. (Port is exposed correctly)
  2. Open the csharp module in VSCode, and inject the connection, certificate value as environment variable
  3. Run the csharp module, error from edgeHub

Closing AMQP device proxy for mylaptop2/target because no handler was registered.
Microsoft.Azure.Devices.Edge.Hub.Core.MultipleConnectionsException: Multiple connections detected for device mylaptop2/target

Tried to investigate, it seems the issue is caused by
https://github.com/Azure/azure-iot-sdk-csharp/blob/master/iothub/device/src/Transport/Mqtt/MqttTransportHandler.cs#L942

It creates multiple connections in one session and cause the failure

related to the fix of issue #495

area-edge investigation-required

All 11 comments

@adashen please add a link to the tutorial that you are following.
I followed https://docs.microsoft.com/en-us/azure/iot-edge/how-to-develop-csharp-module and everything except attaching a debugger works as expected. (Opened https://github.com/MicrosoftDocs/azure-docs/issues/11450 to track the debugging issues.)

@CIPop The bug is reproduced when running module code on host machine instead of docker container. And the scenario is important for local developing and debugging. The difference is

  1. In docker container, in the network created only one ip could be parsed by the edgehub Alias.
  2. On host, the FQDN (which is same as the alias) could be parsed to several IPs and the issue shows up.

The bug is reproduced when running module code on host machine instead of docker container.
And the scenario is important for local developing and debugging.

I agree but I can't find any documentation on how to achieve that. (@varunpuranik / @damonbarry - is this officially supported? If yes, could you add instructions here please?)

@adashen As far as I understand, Edge has two classes of connections: inbound from modules (MQTT) and outbound towards IoTHub (AMQP). From your report it's unclear which of these throws the exception and how the IoT SDK is involved (the exception name points at Edge code, which is not part of this SDK: Microsoft.Azure.Devices.Edge.Hub.Core.MultipleConnectionsException.
We've tested #495 by modifying the hosts file to contain several addresses for a host. If you are able to isolate a repro that way, it would be easy to give it a try on my end.

@adashen The MultipleConnectionsException happens in Edge Hub when a device connects and the Edge Hub already has an active connection for a device with that device ID. Are you sure you didn't accidentally have two instances of the module running? For example, one instance in Visual Studio and another instance in Docker? Or one from the command line or a previous Ctrl+F5 in VS, and the new one in VS?

Yes, you should be able to run a module outside a container; interactions between modules and Edge Hub are strictly through network comms, so the module's app architecture doesn't matter.

Yes, you should be able to run a module outside a container; interactions between modules and Edge Hub are strictly through network comms, so the module's app architecture doesn't matter.

@damonbarry Can you share instructions on how to do that? There are quite a few environment variables that need to be set to make this work.

@CIPop the protocol is MQTT. And I thought the related code is
https://github.com/Azure/azure-iot-sdk-csharp/blob/master/iothub/device/src/Transport/Mqtt/MqttTransportHandler.cs#L947
this line. It is in a for loop, and each matched ip will ask for a connection.

Looks like the fix should be to return the channel right away, if ConnectAsync succeeds without throwing.

Can you share instructions on how to do that? There are quite a few environment variables that need to be set to make this work.

@CIPop Actually, @adashen could probably answer that question better than I can. :) But the easiest way I know of (in develop/debug scenarios ONLY, since it bypasses the security daemon and cert validation) is to:

  1. Set the environment variable EdgeHubConnectionString in your environment
  2. Disable server-side cert validation in the ITransportSettings[] argument that you pass to Microsoft.Azure.Devices.Client.ModuleClient.CreateFromEnvironmentAsync

@CIPop we have a local edge under development. You could leverage this tool for your testing. Install the pre-release version tool
pip install --index-url https://test.pypi.org/simple/ iotedgehubdev --extra-index-url https://pypi.org/simple

And refer to the https://github.com/Azure/iotedgehubdev/blob/master/README.md#quickstart for the steps

@adashen if you already have the setup, please give #551 a try to ensure this is solving your issue.

Just tried the new version 1.17.1. It seems the fix cause other issue. When there are multiple ip matched . But the first connect try throws error. It just returns and there is no channel. Comment added at https://github.com/Azure/azure-iot-sdk-csharp/pull/551/files#diff-1490bd8ef1099d0eb857b65d89056e49R959

Was this page helpful?
0 / 5 - 0 ratings