Skip to content

Commit

Permalink
use ping and less verbose stack traces
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelveldt committed Feb 28, 2024
1 parent 3bc8387 commit 929646e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 29 deletions.
18 changes: 15 additions & 3 deletions matter_server/server/client_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,24 @@ async def _run_handler(
result = await result
self._send_message(SuccessResultMessage(msg.message_id, result))
except ChipStackError as err:
self._logger.exception("SDK Error during handling message: %s", msg)
self._logger.error(
"SDK Error during handling message: %s: %s",
msg.command,
str(err),
# only print the full stacktrace if debug logging is enabled
exc_info=err if self._logger.isEnabledFor(logging.DEBUG) else None,
)
self._send_message(
ErrorResultMessage(msg.message_id, SDKStackError.error_code, str(err))
)
except Exception as err: # pylint: disable=broad-except
self._logger.exception("Error handling message: %s", msg)
except Exception as err: # pylint: disable=broad-except # noqa: BLE001
self._logger.error(
"SDK Error during handling message: %s: %s",
msg.command,
str(err),
# only print the full stacktrace if debug logging is enabled
exc_info=err if self._logger.isEnabledFor(logging.DEBUG) else None,
)
error_code = getattr(err, "error_code", MatterError.error_code)
self._send_message(ErrorResultMessage(msg.message_id, error_code, str(err)))

Expand Down
55 changes: 29 additions & 26 deletions matter_server/server/device_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -970,30 +970,25 @@ def resubscription_succeeded(
self._last_subscription_attempt[node_id] = 0
future = loop.create_future()
device = await self._resolve_node(node_id)
try:
Attribute.Read(
future=future,
eventLoop=loop,
device=device.deviceProxy,
devCtrl=self.chip_controller,
attributes=[Attribute.AttributePath()], # wildcard
events=[
Attribute.EventPath(
EndpointId=None, Cluster=None, Event=None, Urgent=1
)
],
returnClusterObject=False,
subscriptionParameters=Attribute.SubscriptionParameters(
interval_floor, interval_ceiling
),
# Use fabricfiltered as False to detect changes made by other controllers
# and to be able to provide a list of all fabrics attached to the device
fabricFiltered=False,
autoResubscribe=True,
).raise_on_error()
sub: Attribute.SubscriptionTransaction = await future
except Exception as err: # pylint: disable=broad-except
node_logger.exception("Error setting up subscription", exc_info=err)
Attribute.Read(
future=future,
eventLoop=loop,
device=device.deviceProxy,
devCtrl=self.chip_controller,
attributes=[Attribute.AttributePath()], # wildcard
events=[
Attribute.EventPath(EndpointId=None, Cluster=None, Event=None, Urgent=1)
],
returnClusterObject=False,
subscriptionParameters=Attribute.SubscriptionParameters(
interval_floor, interval_ceiling
),
# Use fabricfiltered as False to detect changes made by other controllers
# and to be able to provide a list of all fabrics attached to the device
fabricFiltered=False,
autoResubscribe=True,
).raise_on_error()
sub: Attribute.SubscriptionTransaction = await future

sub.SetAttributeUpdateCallback(attribute_updated_callback)
sub.SetEventUpdateCallback(event_callback)
Expand Down Expand Up @@ -1041,8 +1036,16 @@ async def _setup_node(self, node_id: int) -> None:
# prevent duplicate setup actions
return
self._nodes_in_setup.add(node_id)
# pre-cache ip-addresses
await self.get_node_ip_addresses(node_id)
# ping the node to out stale mdns reports and to prevent that we
# send an unreachable node to the sdk which is very slow with resolving it
# this will also precache the ip addresses of the node for later use.
ping_result = await self.ping_node(node_id)
if not any(ping_result.values()):
LOGGER.warning(
"Skip set-up for node %s because it does not appear to be reachable...",
node_id,
)
return
# we use a lock for the node setup process to process nodes sequentially
# to prevent a flood of the (thread) network when there are many nodes being setup.
async with self._node_setup_lock:
Expand Down

0 comments on commit 929646e

Please sign in to comment.