@@ -263,29 +263,31 @@ async def async_check_service(
263263 await self .async_wait (random .randint (* _PROBE_RANDOM_DELAY_INTERVAL )) # noqa: S311
264264
265265 next_instance_number = 2
266- next_time = now = current_time_millis ()
267- i = 0
268- while i < _REGISTER_BROADCASTS :
269- # check for a name conflict
270- while self .cache .current_entry_with_name_and_alias (info .type , info .name ):
266+ probes_sent = 0
267+ next_probe_at = current_time_millis ()
268+ while probes_sent < _REGISTER_BROADCASTS :
269+ # check for a name conflict; a cache update during the wait below
270+ # wakes async_wait, so a conflicting response lands here promptly
271+ if self .cache .current_entry_with_name_and_alias (info .type , info .name ):
271272 if not allow_name_change :
272273 raise NonUniqueNameException
273274
274- # change the name and look for a conflict
275+ # change the name and restart probing from zero
275276 info .name = f"{ instance_name } -{ next_instance_number } .{ info .type } "
276277 next_instance_number += 1
277278 service_type_name (info .name , strict = strict )
278- next_time = now
279- i = 0
279+ probes_sent = 0
280+ next_probe_at = current_time_millis ()
281+ continue
280282
281- if now < next_time :
282- await self . async_wait ( next_time - now )
283- now = current_time_millis ( )
283+ remaining = next_probe_at - current_time_millis ()
284+ if remaining > 0 :
285+ await self . async_wait ( remaining )
284286 continue
285287
286288 self .async_send (self .generate_service_query (info ))
287- i += 1
288- next_time += _CHECK_TIME
289+ probes_sent += 1
290+ next_probe_at += _CHECK_TIME
289291
290292 async def async_get_service_info (
291293 self ,
0 commit comments