@@ -958,10 +958,9 @@ def resubscription_attempted(
958
958
# we debounce it a bit so we only mark the node unavailable
959
959
# at the second resubscription attempt
960
960
if node .available and self ._last_subscription_attempt [node_id ] >= 1 :
961
- node .available = False
962
961
# NOTE: if the node is (re)discovered by mdns, that callback will
963
962
# take care of resubscribing to the node
964
- self . server . signal_event ( EventType . NODE_UPDATED , node )
963
+ asyncio . create_task ( self . _node_offline ( node_id ) )
965
964
self ._last_subscription_attempt [node_id ] += 1
966
965
967
966
def resubscription_succeeded (
@@ -1219,15 +1218,7 @@ async def _on_mdns_operational_node_state(
1219
1218
if not node .available :
1220
1219
return # node is already offline, nothing to do
1221
1220
LOGGER .info ("Node %s vanished according to MDNS" , node_id )
1222
- # Remove and cancel any existing interview/subscription reschedule timer
1223
- if existing := self ._sub_retry_timer .pop (node_id , None ):
1224
- existing .cancel ()
1225
- # shutdown existing subscriptions
1226
- if sub := self ._subscriptions .pop (node_id , None ):
1227
- await self ._call_sdk (sub .Shutdown )
1228
- # mark node as unavailable
1229
- node .available = False
1230
- self .server .signal_event (EventType .NODE_UPDATED , node_id )
1221
+ await self ._node_offline (node_id )
1231
1222
finally :
1232
1223
self ._mdns_inprogress .remove (node_id )
1233
1224
@@ -1256,3 +1247,18 @@ def _write_node_state(self, node_id: int, force: bool = False) -> None:
1256
1247
subkey = str (node_id ),
1257
1248
force = force ,
1258
1249
)
1250
+
1251
+ async def _node_offline (self , node_id : int ) -> None :
1252
+ """Mark node as offline."""
1253
+ # Remove and cancel any existing interview/subscription reschedule timer
1254
+ if existing := self ._sub_retry_timer .pop (node_id , None ):
1255
+ existing .cancel ()
1256
+ # shutdown existing subscriptions
1257
+ if sub := self ._subscriptions .pop (node_id , None ):
1258
+ await self ._call_sdk (sub .Shutdown )
1259
+ # mark node as unavailable
1260
+ node = self ._nodes [node_id ]
1261
+ if not node .available :
1262
+ return
1263
+ node .available = False
1264
+ self .server .signal_event (EventType .NODE_UPDATED , node )
0 commit comments