-
Notifications
You must be signed in to change notification settings - Fork 379
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
azure.iot.device.common.transport_exceptions.ConnectionFailedError #1145
Comments
Try adding an If that doesn't help, you'll need to provide more information for us to investigate further - your code, as well as the version of the azure-iot-device SDK you are using. |
Thanks you cartertinney. I will try with adding async.sleep(5) and let you know the out come. Mean while here is my code and deployment files and versions. Version Infoazure-iot-device~=2.7.0 Copyright (c) Microsoft. All rights reserved.Licensed under the MIT license. See LICENSE file in the project root forfull license information.import asyncio global countersTEMPERATURE_THRESHOLD = 25 Event indicating client stopstop_event = threading.Event() def create_client():
async def run_sample(client): def main():
if name == "main": deployment.arm32v7.json |
Full Failure Log follows... root@tcs-imx6:~# iotedge logs gwmodule The above exception was the direct cause of the following exception: Traceback (most recent call last): |
Hi Cartertinney, <6> 2023-05-30 09:49:20.780 +00:00 [INF] - Client tcsgateway1/gwmodule in device scope authenticated locally. |
You need to Additionally, in the future, please format your code and logs by using adding ``` before and after. That's three ` characters. |
Edge Module getting disconnected with " <4> 2023-05-31 10:03:38.355 +00:00 [WRN] - "Closing connection for device: tcsgateway1/gwmodule, Microsoft.Azure.Devices.ProtocolGateway.ProtocolGatewayException: Channel closed., " Logs from edgeHub follows..
Logs from Edge Module "gwmodule" follows...
My Python Code for Edge Module follows..
|
My apologies - I made a mistake. Seeing the better formatted logs and code make it clear to me. You're now running into an issue with the async event loop because of what I said to you - You should keep main as a synchronous function ( def main():
if not sys.version >= "3.5.3":
raise Exception( "The sample requires python 3.5.3+. Current version of Python: %s" % sys.version )
print ( "IoT Hub Client for Python" )
time.sleep(5)
<....>
if __name__ == "__main__":
main() Additionally, when formatting, please use backticks (`) not apostrophes ('). I have edited your post accordingly for correct formatting. |
Thank you.. But still the issue continues. The connection between my Edge Module "gwmodule" and the edgeHub is getting dropped with in 3 to 4 sec. Saying "Protocol Gateway Exception"
|
@ramumr06 - I recommend you change the password on your container repository. You accidentally leaked it in the deployment manifest above. If that password gives write access to the repository, I recommend destroying the repository and creating a new one from scratch. |
@BertKleewein - I will update the registry password. This is just to secure my registry right? |
Hi @ramumr06 , yes, my comment was only about securing your registry. Logs from edgehub don't really help. logs form your gwmodule are more useful, but I 'm not sure what you mean when you say "Still the issue continues". Do you mean you're still seeing the The The |
The "Event Loop" Issue resolved. Even the hostname is defined in the config.toml file. My other Edge Module SimulatedTemperatureSensor from azure market working fine. edgeHub log showing following error..
|
Hello guys, Having the same issue too, and I tried the time.sleep(5) trick. I have been having that same issue for a long time now, and only on python modules, whenever the module is hard shutdown, without executing the shutdown function, for example when the device is unplugged. Main function: ##################################
# Main function / Env settler
##################################
def main():
""" Main function.
Is used to setup the whole module.
"""
if not sys.version >= "3.5.3":
raise Exception( "The module requires python 3.5.3+. Current version of Python: %s" % sys.version )
log("IoT Hub Client for Python" )
time.sleep(5)
# NOTE: Client is implicitly connected due to the handler being set on it
client = create_client()
# Define a handler to cleanup when module is is terminated by Edge
def module_termination_handler(signal, frame):
log("IoTHubClient stopped by Edge")
stop_event.set()
# Set the Edge termination handler
signal.signal(signal.SIGTERM, module_termination_handler)
# Run
loop = asyncio.get_event_loop()
try:
loop.run_until_complete(run_module(client))
except Exception as e:
log("Unexpected error %s " % e)
raise
finally:
log("Shutting down IoT Hub Client...")
loop.run_until_complete(client.shutdown())
loop.stop()
loop.close()
if __name__ == "__main__":
main() Module logs: Before adding the time.sleep(5)
After adding the time.sleep(5)
|
Hi All,
I have built (docker based image) Python based Sample Edge module and deployed on to my ARM based Edge device i.e Gateway. This edge module thrown following errors When i executed "iotedge restart gwmodule" command.
root@tcs-imx6:~# iotedge logs gwmodule
IoT Hub Client for Python
Subscribe for input failed. Not enabling feature
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/azure/iot/device/common/mqtt_transport.py", line 396, in connect
host=self._hostname, port=8883, keepalive=self._keep_alive
File "/usr/local/lib/python3.7/site-packages/paho/mqtt/client.py", line 914, in connect
return self.reconnect()
File "/usr/local/lib/python3.7/site-packages/paho/mqtt/client.py", line 1044, in reconnect
sock = self._create_socket_connection()
File "/usr/local/lib/python3.7/site-packages/paho/mqtt/client.py", line 3685, in _create_socket_connection
return socket.create_connection(addr, timeout=self._connect_timeout, source_address=source)
File "/usr/local/lib/python3.7/socket.py", line 707, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "/usr/local/lib/python3.7/socket.py", line 752, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "./main.py", line 102, in
main()
File "./main.py", line 78, in main
client = create_client()
File "./main.py", line 55, in create_client
client.on_message_received = receive_message_handler
File "/usr/local/lib/python3.7/site-packages/azure/iot/device/iothub/sync_clients.py", line 772, in on_message_received
"on_message_received", pipeline_constant.INPUT_MSG, value
File "/usr/local/lib/python3.7/site-packages/azure/iot/device/iothub/sync_clients.py", line 504, in _generic_receive_handler_setter
self._enable_feature(feature_name)
File "/usr/local/lib/python3.7/site-packages/azure/iot/device/iothub/sync_clients.py", line 113, in _enable_feature
callback.wait_for_completion()
File "/usr/local/lib/python3.7/site-packages/azure/iot/device/common/evented_callback.py", line 70, in wait_for_completion
raise self.exception
File "/usr/local/lib/python3.7/site-packages/azure/iot/device/common/pipeline/pipeline_stages_mqtt.py", line 193, in _run_op
self.transport.connect(password=password)
File "/usr/local/lib/python3.7/site-packages/azure/iot/device/common/mqtt_transport.py", line 418, in connect
raise exceptions.ConnectionFailedError(cause=e)
azure.iot.device.common.transport_exceptions.ConnectionFailedError: ConnectionFailedError(None) caused by gaierror(-2, 'Name or service not known')
#########################
Few of my workspace details.. I mentioned PythonModule in Last line of the deployment.json . Do i need to change it to "SampleModule" .
tcs@tcs-Latitude-5590:
/new-workspace/azure-build/EdgeSolution/modules/SampleModule$ ls/new-workspace/azure-build/EdgeSolution/modules/SampleModule$ cat ../../config/deployment.arm32v7.jsonDockerfile.amd64 Dockerfile.arm32v7 Dockerfile.arm32v7-OLD Dockerfile.arm64v8.debug module.json requirements.txt
Dockerfile.amd64.debug Dockerfile.arm32v7.debug Dockerfile.arm64v8 main.py other-main.py
tcs@tcs-Latitude-5590:
{
"modulesContent": {
"$edgeAgent": {
"properties.desired": {
"schemaVersion": "1.4",
"runtime": {
"type": "docker",
"settings": {
"minDockerVersion": "v1.25",
"loggingOptions": "",
"registryCredentials": {
"ipsscr": {
"username": "ipsscr",
"password": "******",
"address": "#######"
}
}
}
},
"systemModules": {
"edgeAgent": {
"type": "docker",
"settings": {
"image": "mcr.microsoft.com/azureiotedge-agent:1.4",
"createOptions": "{}"
}
},
"edgeHub": {
"type": "docker",
"status": "running",
"restartPolicy": "always",
"settings": {
"image": "mcr.microsoft.com/azureiotedge-hub:1.4",
"createOptions": "{"HostConfig":{"PortBindings":{"5671/tcp":[{"HostPort":"5671"}],"8883/tcp":[{"HostPort":"8883"}],"443/tcp":[{"HostPort":"443"}]}}}"
}
}
},
"modules": {
"SampleModule": {
"version": "1.0",
"type": "docker",
"status": "running",
"restartPolicy": "always",
"settings": {
"image": "ipsscr.azurecr.io/gwmodule:0.0.1-arm32v7",
"createOptions": "{}"
}
},
"SimulatedTemperatureSensor": {
"version": "1.0",
"type": "docker",
"status": "running",
"restartPolicy": "always",
"settings": {
"image": "mcr.microsoft.com/azureiotedge-simulated-temperature-sensor:1.4",
"createOptions": "{}"
}
}
}
}
},
"$edgeHub": {
"properties.desired": {
"schemaVersion": "1.4",
"routes": {
"SampleModuleToIoTHub": "FROM /messages/modules/SampleModule/outputs/ INTO $upstream",
"sensorToSampleModule": "FROM /messages/modules/SimulatedTemperatureSensor/outputs/temperatureOutput INTO BrokeredEndpoint("/modules/SampleModule/inputs/input1")"
},
"storeAndForwardConfiguration": {
"timeToLiveSecs": 7200
}
}
},
"PythonModule": {
"properties.desired": {
"TemperatureThreshold": 25
}
}
}
}
The text was updated successfully, but these errors were encountered: