Skip to content

Commit a62bd0e

Browse files
committed
maybe a fix?
1 parent 2d1586d commit a62bd0e

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

‎azure-iot-device/azure/iot/device/common/pipeline/pipeline_stages_mqtt.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,16 @@ def _run_op(self, op):
224224
# The connect after the disconnect will be triggered upon completion of the
225225
# disconnect in the on_disconnected handler
226226
self.transport.disconnect(clear_inflight=op.hard)
227+
except transport_exceptions.NoConnectionError:
228+
# If we're already disconnected, that's fine - we wanted to
229+
# disconnect and we're disconnected. Treat this as success, not an error.
230+
# This can happen in race conditions where the socket was cleaned up before
231+
# the explicit disconnect call, particularly when callbacks trigger client disconnects.
232+
logger.info(
233+
"transport.disconnect raised NoConnectionError - already disconnected, treating as success"
234+
)
235+
self._pending_connection_op = None
236+
op.complete()
227237
except Exception as e:
228238
logger.info("transport.disconnect raised error while disconnecting")
229239
logger.info(traceback.format_exc())

0 commit comments

Comments
 (0)