================
@@ -250,6 +251,13 @@ def which(program):
     return None
 
 
+def pickrandomport():
+    """Returns a random open port."""
+    with socket.socket() as sock:
+        sock.bind(("", 0))
+        return sock.getsockname()[1]
----------------
labath wrote:

Indeed. I am not very fond of interfaces like this. Not only you have a race in 
grabbing the port, you also have a race in connecting to it (you don't know 
when the other process has actually started listening on it). 

I'd really like to do this in a race-free way. Am I correct in assuming that we 
control both sides of this protocol? lldb-server server has a mode where *it* 
selects the port it is listening on and then notifies its parent of the address 
(by writing it to a pipe or something). This solves both races because there's 
no way to snatch the port from under it, and the port message also serves as 
confirmation of the fact that it has started listening. An alternative (which 
may be harder to achieve if the other side is some higher level language) is to 
open the socket on one side and pass the opened listening socket to lldb-dap 
(we're doing something similar for lldb-platform subprocesses now, but those 
are both written in C).

https://github.com/llvm/llvm-project/pull/116392
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to