Skip to content

Commit 5128f44

Browse files
authored
detect if port is used on IPV6 (#5508)
1 parent 551c5c4 commit 5128f44

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

reflex/utils/processes.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,16 @@ def is_process_on_port(port: int) -> bool:
6161
Returns:
6262
Whether a process is running on the given port.
6363
"""
64+
# Test IPv4 localhost (127.0.0.1)
6465
with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as sock:
65-
return sock.connect_ex(("127.0.0.1", port)) == 0
66+
ipv4_result = sock.connect_ex(("127.0.0.1", port)) == 0
67+
68+
# Test IPv6 localhost (::1)
69+
with closing(socket.socket(socket.AF_INET6, socket.SOCK_STREAM)) as sock:
70+
ipv6_result = sock.connect_ex(("::1", port)) == 0
71+
72+
# Port is in use if either IPv4 or IPv6 is listening
73+
return ipv4_result or ipv6_result
6674

6775

6876
def change_port(port: int, _type: str) -> int:

0 commit comments

Comments
 (0)