Ignore disappearing network devices while querying them (#3249)

Sometimes NetworkManager network devices disappear while we are query
them. Presumably those are network interfaces generated by Docker.
Skip them and print a warning.
This commit is contained in:
Stefan Agner 2021-10-20 15:06:36 +02:00 committed by GitHub
parent e5817e9445
commit d2b706df05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View File

@ -13,6 +13,7 @@ from ...exceptions import (
DBusError,
DBusFatalError,
DBusInterfaceError,
DBusInterfaceMethodError,
HostNotSupportedError,
)
from ...utils.dbus import DBus
@ -162,7 +163,10 @@ class NetworkManager(DBusInterface):
# Connect to interface
try:
await interface.connect()
except DBusFatalError as err:
except (DBusFatalError, DBusInterfaceMethodError) as err:
# Docker creates and deletes interfaces quite often, sometimes
# this causes a race condition: A device disappears while we
# try to query it. Ignore those cases.
_LOGGER.warning("Can't process %s: %s", device, err)
continue
except Exception as err: # pylint: disable=broad-except

View File

@ -162,11 +162,10 @@ class DBus:
)
if reply.message_type == MessageType.ERROR:
if reply.error_name in (
"org.freedesktop.DBus.Error.ServiceUnknown",
"org.freedesktop.DBus.Error.UnknownMethod",
):
if reply.error_name == "org.freedesktop.DBus.Error.ServiceUnknown":
raise DBusInterfaceError(reply.body[0])
if reply.error_name == "org.freedesktop.DBus.Error.UnknownMethod":
raise DBusInterfaceMethodError(reply.body[0])
if reply.error_name == "org.freedesktop.DBus.Error.Disconnected":
raise DBusNotConnectedError()
if reply.body and len(reply.body) > 0: