@@ -118,6 +118,7 @@ def __init__(
118
118
self ._sdk_executor = ThreadPoolExecutor (
119
119
max_workers = 1 , thread_name_prefix = "SDKExecutor"
120
120
)
121
+ self ._node_setup_throttle = asyncio .Semaphore (10 )
121
122
122
123
async def initialize (self ) -> None :
123
124
"""Async initialize of controller."""
@@ -1070,53 +1071,56 @@ async def _setup_node(self, node_id: int) -> None:
1070
1071
return
1071
1072
self ._nodes_in_setup .add (node_id )
1072
1073
try :
1073
- # Ping the node to rule out stale mdns reports and to prevent that we
1074
- # send an unreachable node to the sdk which is very slow with resolving it.
1075
- # This will also precache the ip addresses of the node for later use.
1076
- ping_result = await self .ping_node (
1077
- node_id , attempts = 3 , allow_cached_ips = False
1078
- )
1079
- if not any (ping_result .values ()):
1080
- LOGGER .warning (
1081
- "Skip set-up for node %s because it does not appear to be reachable..." ,
1082
- node_id ,
1074
+ async with self ._node_setup_throttle :
1075
+ # Ping the node to rule out stale mdns reports and to prevent that we
1076
+ # send an unreachable node to the sdk which is very slow with resolving it.
1077
+ # This will also precache the ip addresses of the node for later use.
1078
+ ping_result = await self .ping_node (
1079
+ node_id , attempts = 3 , allow_cached_ips = False
1083
1080
)
1084
- return
1085
- LOGGER .info ("Setting-up node %s..." , node_id )
1086
- # (re)interview node (only) if needed
1087
- node_data = self ._nodes [node_id ]
1088
- if (
1089
- # re-interview if we dont have any node attributes (empty node)
1090
- not node_data .attributes
1091
- # re-interview if the data model schema has changed
1092
- or node_data .interview_version != DATA_MODEL_SCHEMA_VERSION
1093
- ):
1081
+ if not any (ping_result .values ()):
1082
+ LOGGER .warning (
1083
+ "Skip set-up for node %s because it does not appear to be reachable..." ,
1084
+ node_id ,
1085
+ )
1086
+ return
1087
+ LOGGER .info ("Setting-up node %s..." , node_id )
1088
+ # (re)interview node (only) if needed
1089
+ node_data = self ._nodes [node_id ]
1090
+ if (
1091
+ # re-interview if we dont have any node attributes (empty node)
1092
+ not node_data .attributes
1093
+ # re-interview if the data model schema has changed
1094
+ or node_data .interview_version != DATA_MODEL_SCHEMA_VERSION
1095
+ ):
1096
+ try :
1097
+ await self .interview_node (node_id )
1098
+ except (NodeNotResolving , NodeInterviewFailed ) as err :
1099
+ LOGGER .warning (
1100
+ "Unable to interview Node %s: %s" ,
1101
+ node_id ,
1102
+ str (err ) or err .__class__ .__name__ ,
1103
+ # log full stack trace if debug logging is enabled
1104
+ exc_info = err
1105
+ if LOGGER .isEnabledFor (logging .DEBUG )
1106
+ else None ,
1107
+ )
1108
+ # NOTE: the node will be picked up by mdns discovery automatically
1109
+ # when it comes available again.
1110
+ return
1111
+ # setup subscriptions for the node
1094
1112
try :
1095
- await self .interview_node (node_id )
1096
- except (NodeNotResolving , NodeInterviewFailed ) as err :
1113
+ await self ._subscribe_node (node_id )
1114
+ except (NodeNotResolving , ChipStackError ) as err :
1097
1115
LOGGER .warning (
1098
- "Unable to interview Node %s: %s" ,
1116
+ "Unable to subscribe to Node %s: %s" ,
1099
1117
node_id ,
1100
1118
str (err ) or err .__class__ .__name__ ,
1101
1119
# log full stack trace if debug logging is enabled
1102
1120
exc_info = err if LOGGER .isEnabledFor (logging .DEBUG ) else None ,
1103
1121
)
1104
1122
# NOTE: the node will be picked up by mdns discovery automatically
1105
- # when it comes available again.
1106
- return
1107
- # setup subscriptions for the node
1108
- try :
1109
- await self ._subscribe_node (node_id )
1110
- except (NodeNotResolving , ChipStackError ) as err :
1111
- LOGGER .warning (
1112
- "Unable to subscribe to Node %s: %s" ,
1113
- node_id ,
1114
- str (err ) or err .__class__ .__name__ ,
1115
- # log full stack trace if debug logging is enabled
1116
- exc_info = err if LOGGER .isEnabledFor (logging .DEBUG ) else None ,
1117
- )
1118
- # NOTE: the node will be picked up by mdns discovery automatically
1119
- # when it becomes available again.
1123
+ # when it becomes available again.
1120
1124
finally :
1121
1125
self ._nodes_in_setup .discard (node_id )
1122
1126
0 commit comments