Azure / iotedgehubdev

IoT Edge Hub Dev Tool
Other
87 stars 30 forks source link

Modules not connecting to Edgehub on Azure ML Compute Instance (Developer Environment) #384

Open rajaasokan opened 2 years ago

rajaasokan commented 2 years ago

We are trying to get our development environment with iotedgedevhub in running in an Azure ML Compute Instance (because it is already used extensively in our development processes, it offers GPU options we need for our use case and the integration of VS Code is superb).

Unfortunately when we try to debug our solution (which works on many other devices we tested them on) we receive an error: 'Cannot assign request address'. We have the feeling that problem is either Docker Environment or Networking related but are struggling to find the reason.

Logs from module:

SceletonModule                | User's Environment variable:
SceletonModule                | IoT Hub Client for Python
SceletonModule                | Subscribe for input failed.  Not enabling feature
SceletonModule                | ./main.py:38: RuntimeWarning: coroutine 'execute_patch_for_async.<locals>.shutdown' was never awaited
SceletonModule                |   client.shutdown()
SceletonModule                | RuntimeWarning: Enable tracemalloc to get the object allocation traceback
SceletonModule                | Traceback (most recent call last):
SceletonModule                |   File "/usr/local/lib/python3.8/dist-packages/azure/iot/device/common/mqtt_transport.py", line 395, in connect
SceletonModule                |     rc = self._mqtt_client.connect(
SceletonModule                |   File "/usr/local/lib/python3.8/dist-packages/paho/mqtt/client.py", line 914, in connect
SceletonModule                |     return self.reconnect()
SceletonModule                |   File "/usr/local/lib/python3.8/dist-packages/paho/mqtt/client.py", line 1044, in reconnect
SceletonModule                |     sock = self._create_socket_connection()
SceletonModule                |   File "/usr/local/lib/python3.8/dist-packages/paho/mqtt/client.py", line 3685, in _create_socket_connection
SceletonModule                |     return socket.create_connection(addr, timeout=self._connect_timeout, source_address=source)
SceletonModule                |   File "/usr/lib/python3.8/socket.py", line 807, in create_connection
SceletonModule                |     raise err
SceletonModule                |   File "/usr/lib/python3.8/socket.py", line 796, in create_connection
SceletonModule                |     sock.connect(sa)
SceletonModule                | OSError: [Errno 99] Cannot assign requested address
SceletonModule                |
SceletonModule                | The above exception was the direct cause of the following exception:
SceletonModule                |
SceletonModule                | Traceback (most recent call last):
SceletonModule                |   File "/usr/local/lib/python3.8/dist-packages/azure/iot/device/iothub/aio/async_clients.py", line 33, in handle_result
SceletonModule                |     return await callback.completion()
SceletonModule                |   File "/usr/local/lib/python3.8/dist-packages/azure/iot/device/common/async_adapter.py", line 91, in completion
SceletonModule                |     return await self.future
SceletonModule                |   File "/usr/local/lib/python3.8/dist-packages/azure/iot/device/common/pipeline/pipeline_stages_mqtt.py", line 199, in _run_op
SceletonModule                |     self.transport.connect(password=password)
SceletonModule                |   File "/usr/local/lib/python3.8/dist-packages/azure/iot/device/common/mqtt_transport.py", line 418, in connect
SceletonModule                |     raise exceptions.ConnectionFailedError(cause=e)
SceletonModule                | azure.iot.device.common.transport_exceptions.ConnectionFailedError: ConnectionFailedError(None) caused by OSError(99, 'Cannot assign requested address')
SceletonModule                |
SceletonModule                | The above exception was the direct cause of the following exception:
SceletonModule                |
SceletonModule                | Traceback (most recent call last):
SceletonModule                |   File "./main.py", line 84, in <module>
SceletonModule                |     main()
SceletonModule                |   File "./main.py", line 57, in main
SceletonModule                |     client = create_client()
SceletonModule                |   File "./main.py", line 35, in create_client
SceletonModule                |     client.on_message_received = receive_message_handler
SceletonModule                |   File "/usr/local/lib/python3.8/dist-packages/azure/iot/device/iothub/abstract_clients.py", line 875, in on_message_received
SceletonModule                |     self._generic_receive_handler_setter(
SceletonModule                |   File "/usr/local/lib/python3.8/dist-packages/azure/iot/device/iothub/aio/async_clients.py", line 161, in _generic_receive_handler_setter
SceletonModule                |     fut.result()
SceletonModule                |   File "/usr/lib/python3.8/concurrent/futures/_base.py", line 439, in result
SceletonModule                |     return self.__get_result()
SceletonModule                |   File "/usr/lib/python3.8/concurrent/futures/_base.py", line 388, in __get_result
SceletonModule                |     raise self._exception
SceletonModule                |   File "/usr/local/lib/python3.8/dist-packages/azure/iot/device/iothub/aio/async_clients.py", line 113, in _enable_feature
SceletonModule                |     await handle_result(callback)
SceletonModule                |   File "/usr/local/lib/python3.8/dist-packages/azure/iot/device/iothub/aio/async_clients.py", line 37, in handle_result
SceletonModule                |     raise exceptions.ConnectionFailedError(message="Could not connect to IoTHub", cause=e)
SceletonModule                | azure.iot.device.exceptions.ConnectionFailedError: ConnectionFailedError('Could not connect to IoTHub') caused by ConnectionFailedError(None)
SceletonModule                | Task was destroyed but it is pending!
SceletonModule                | task: <Task pending name='Task-7' coro=<AsyncHandlerManager._receiver_handler_runner() running at /usr/local/lib/python3.8/dist-packages/azure/iot/device/iothub/aio/async_handler_manager.py:43> wait_for=<Future pending cb=[_chain_future.<locals>._call_check_cancel() at /usr/lib/python3.8/asyncio/futures.py:357, <TaskWakeupMethWrapper object at 0x7fbdf2a581f0>()]> cb=[_chain_future.<locals>._call_set_state() at /usr/lib/python3.8/asyncio/futures.py:364]>
SceletonModule                | Task was destroyed but it is pending!
SceletonModule                | task: <Task pending name='Task-8' coro=<_AsyncQueueProxy.get() running at /usr/local/lib/python3.8/dist-packages/janus/__init__.py:552> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7fbdf2a4ffa0>()]> cb=[_chain_future.<locals>._call_set_state() at /usr/lib/python3.8/asyncio/futures.py:364]>
konichi3 commented 2 years ago

Hi @rajaasokan

IoTEdgeHubDev is an Azure IoT Edge (specifically $EdgeHub module) simulator which handles the message routing from the custom module(s).

The issue you described does not look like it is related to IoTEdgeHubDev itself. I assume the problem you are encoutering also occurs on the physical device or VM which runs IoT Edge runtime as well. Please let us know if you think otherwise.

Having said that, there are several reports on Stackoverflow on the issue which is related to socket connection that you might want to reference.

https://stackoverflow.com/search?q=can+not+assign+requested+address+python

rajaasokan commented 2 years ago

Hi @konichi3 Thanks for the response.

The problem we are encountering only occurs when we use a compute instance from Azure ML as development environment. It works without error on a physical device or any other VMs.

We are using Azure ML compute instance as a development environment for IoT Edge solutions.