Skip to content

Commit f7164e8

Browse files
committed
Fix port allocation race condition in cluster tests
1 parent 7e86c12 commit f7164e8

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

nats-server/src/nats/server/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,10 +386,12 @@ async def run_cluster(
386386
# Create socket pairs for each node to reserve both client and cluster ports
387387
for _ in range(size):
388388
client_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
389+
client_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
389390
client_sock.bind(("127.0.0.1", 0))
390391
client_port = client_sock.getsockname()[1]
391392

392393
cluster_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
394+
cluster_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
393395
cluster_sock.bind(("127.0.0.1", 0))
394396
cluster_port = cluster_sock.getsockname()[1]
395397

0 commit comments

Comments
 (0)