Skip to content

The agent that grows with you

docs(whatsapp): state port_is_free's REUSEADDR contract

Teknium7d9f04469b52
diff --git a/plugins/platforms/whatsapp/bridge_ownership.py b/plugins/platforms/whatsapp/bridge_ownership.py
index f8f694fb1e6..c3363582906 100644
--- a/plugins/platforms/whatsapp/bridge_ownership.py
+++ b/plugins/platforms/whatsapp/bridge_ownership.py
@@ -11,6 +11,14 @@ SECONDARY_PORT_LAST = 3999
def port_is_free(port: int) -> bool:
+ """Whether the WhatsApp Node bridge could bind ``port`` on 127.0.0.1 right now.
+
+ Contract: this answers for the bridge's own bind semantics, not for an arbitrary binder. On
+ POSIX the bridge (Express/libuv) sets SO_REUSEADDR, so a port holding only TIME-WAIT entries
+ reads as free here even though a binder without SO_REUSEADDR would get EADDRINUSE; a live
+ listener still reads as busy. Its only callers are this module's bridge-port allocation and
+ ownership checks. Do not reuse it to gate a process that binds without SO_REUSEADDR.
+ """
with socket.socket() as sock:
# A just-stopped bridge can leave its accepted TCP connections in TIME-WAIT. The Node
# bridge enables this option too, so match its bind semantics while still rejecting a listener.