Skip to content

Commit b8c5062

Browse files
committed
fix: increase check time and add random wait to avoid service collisions
1 parent 99ddc08 commit b8c5062

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

src/zeroconf/_core.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import asyncio
2626
import logging
27+
import random
2728
import sys
2829
import threading
2930
from collections.abc import Awaitable
@@ -544,6 +545,11 @@ async def async_check_service(
544545
instance_name = instance_name_from_service_info(info, strict=strict)
545546
if cooperating_responders:
546547
return
548+
549+
# Wait a random amount of time up avoid collisions and avoid
550+
# a thundering herd when multiple services are started on the network
551+
await self.async_wait(random.randint(150, 250))
552+
547553
next_instance_number = 2
548554
next_time = now = current_time_millis()
549555
i = 0

src/zeroconf/const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# Some timing constants
2929

3030
_UNREGISTER_TIME = 125 # ms
31-
_CHECK_TIME = 175 # ms
31+
_CHECK_TIME = 500 # ms
3232
_REGISTER_TIME = 225 # ms
3333
_LISTENER_TIME = 200 # ms
3434
_BROWSER_TIME = 10000 # ms

0 commit comments

Comments
 (0)