Azure / Azure/azure-iot-sdk-python
Disconnects from IoT HuB and does not reconnect
- Vorherrschende Sprache
- Python
- Sterne
- 438
- Forks
- 380
- Ø Merge
- 22 Std. 17 Min.
- Gemergte PRs (30 T.)
- 22
Beschreibung
# Context
- **OS and version used:** Ubuntu inside docker
- **Python version:** 3.10
- **list of installed packages:** azure-appconfiguration 1.7.1 azure-core 1.35.0 azure-iot-device 2.14.0 azure-storage-blob 12.25.1
## Description of the issue
IoT Hub client disconnects in the background thread and unable to reconnect. Our background sends telemetry updates once per second.
This happens with an edge deployment on a sim-card cell connection after some time (usually 20-30 hours). We can see that other services are actually connected to the internet and iot connection is valid because it connects successfully on (re)start.
Related to #996 and bunch of other similar issues.
## Code sample exhibiting the issue
self._client = IoTHubDeviceClient.create_from_connection_string(self.connection_string)
await self._client.connect()
while True:
try:
message = Message(json.dumps(data))
message.content_type = "application/json"
message.content_encoding = "utf-8"
await self._client.send_message(message)
except Exception as e:
logger.error(f"Error in periodic update: {e}")
finally:
await asyncio.sleep(self.update_frequency)
## Console log of the issue
```
Exception caught in background thread. Unable to handle.
['azure.iot.device.common.transport_exceptions.UnauthorizedError: Connection Refused: not authorised.\n']
ConnectionStateStage: DisconnectEvent received while in unexpected state - ConnectionState.DISCONNECTED
Exception caught in background thread. Unable to handle.
['azure.iot.device.common.transport_exceptions.ConnectionDroppedError: Unexpected disconnection\n']
```
Beitragsleitfaden
Rechercherichtung
Beginne damit, die Verbindungsunterbrechung mit der gezeigten IoTHubDeviceClient.create_from_connection_string-, connect- und send_message-Schleife unter Ubuntu in Docker zu reproduzieren, wobei die bereitgestellten Logs des Hintergrundthreads als Fehlersignal verwendet werden. Ermittle, warum der Client sich nach UnauthorizedError oder ConnectionDroppedError nicht wieder erholt; abgeschlossen ist die Aufgabe, wenn die Verbindung wiederhergestellt wird und die periodische Telemetrie fortgesetzt wird, ohne den Prozess neu zu starten.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- azure, python
- Bereich
- cloud, networking
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 30/100