| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -263,29 +263,31 @@ async def async_check_service( | |||
| 263 | 263 | await self.async_wait(random.randint(*_PROBE_RANDOM_DELAY_INTERVAL)) # noqa: S311 | |
| 264 | 264 | ||
| 265 | 265 | 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): | ||
| 271 | 272 | if not allow_name_change: | |
| 272 | 273 | raise NonUniqueNameException | |
| 273 | 274 | ||
| 274 | - # change the name and look for a conflict | ||
| 275 | + # change the name and restart probing from zero | ||
| 275 | 276 | info.name = f"{instance_name}-{next_instance_number}.{info.type}" | |
| 276 | 277 | next_instance_number += 1 | |
| 277 | 278 | 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 | ||
| 280 | 282 | ||
| 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) | ||
| 284 | 286 | continue | |
| 285 | 287 | ||
| 286 | 288 | 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 | ||
| 289 | 291 | ||
| 290 | 292 | async def async_get_service_info( | |
| 291 | 293 | self, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments