[Lldb-commits] [lldb] [lldb-dap] Refactoring lldb-dap port listening mode to allow multiple connections. (PR #116392)
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Mon Nov 18 02:01:50 PST 2024
================
@@ -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
More information about the lldb-commits
mailing list