Skip to content

Commit 695f23b

Browse files
pcmoritzrobertnishihara
authored andcommitted
try again to start plasma manager if there is a port collision (#16)
1 parent 780bbd1 commit 695f23b

File tree

3 files changed

+35
-26
lines changed

3 files changed

+35
-26
lines changed

src/common/common.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535

3636
#define CHECK(COND) CHECKM(COND, "")
3737

38+
/* These are exit codes for common errors that can occur in Ray components. */
39+
#define EXIT_COULD_NOT_BIND_PORT -2
40+
3841
/** This macro indicates that this pointer owns the data it is pointing to
3942
* and is responsible for freeing it. */
4043
#define OWNER

src/plasma/plasma_manager.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,9 @@ void start_server(const char *store_socket_name,
908908
CHECK(g_manager_state);
909909

910910
int remote_sock = bind_inet_sock(port);
911-
CHECKM(remote_sock >= 0, "Unable to bind to manager port");
911+
if (remote_sock < 0) {
912+
exit(EXIT_COULD_NOT_BIND_PORT);
913+
}
912914
int local_sock = bind_ipc_sock(manager_socket_name);
913915
CHECKM(local_sock >= 0, "Unable to bind local manager socket");
914916

@@ -984,7 +986,7 @@ int main(int argc, char *argv[]) {
984986
if (!master_addr) {
985987
LOG_ERR(
986988
"please specify ip address of the current host in the format "
987-
"123.456.789.10 with -m switch");
989+
"123.456.789.10 with -h switch");
988990
exit(-1);
989991
}
990992
if (port == -1) {

src/plasma/test/test.py

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,32 @@ def assert_get_object_equal(unit_test, client1, client2, object_id, memory_buffe
5353
unit_test.assertEqual(client1.get_metadata(object_id)[:],
5454
client2.get_metadata(object_id)[:])
5555

56+
def start_plasma_manager(store_name, host_name, redis_port, use_valgrind=False):
57+
"""Start a plasma manager and return the ports it listens on."""
58+
plasma_manager_executable = os.path.join(os.path.abspath(os.path.dirname(__file__)), "../build/plasma_manager")
59+
num_retries = 5
60+
port = None
61+
process = None
62+
while num_retries >= 0:
63+
port = random.randint(10000, 50000)
64+
command = [plasma_manager_executable,
65+
"-s", store_name,
66+
"-m", host_name,
67+
"-h", "127.0.0.1",
68+
"-p", str(port),
69+
"-r", "{addr}:{port}".format(addr="127.0.0.1", port=redis_port)]
70+
print("Try to start plasma manager on port " + str(port))
71+
if use_valgrind:
72+
process = subprocess.Popen(["valgrind", "--track-origins=yes", "--leak-check=full", "--show-leak-kinds=all", "--error-exitcode=1"] + command)
73+
else:
74+
process = subprocess.Popen(command)
75+
time.sleep(0.1)
76+
# See if the process has terminated
77+
if process.poll() == None:
78+
return process, port
79+
num_retries = num_retries - 1
80+
raise Exception("Couldn't start plasma manager")
81+
5682
# Check if the redis-server binary is present.
5783
redis_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), "../../common/thirdparty/redis-3.2.3/src/redis-server")
5884
if not os.path.exists(redis_path):
@@ -240,30 +266,8 @@ def setUp(self):
240266
time.sleep(0.1)
241267

242268
# Start two PlasmaManagers.
243-
self.port1 = random.randint(10000, 50000)
244-
self.port2 = random.randint(10000, 50000)
245-
plasma_manager_executable = os.path.join(os.path.abspath(os.path.dirname(__file__)), "../build/plasma_manager")
246-
plasma_manager_command1 = [plasma_manager_executable,
247-
"-s", store_name1,
248-
"-m", manager_name1,
249-
"-h", "127.0.0.1",
250-
"-p", str(self.port1),
251-
"-r", "{addr}:{port}".format(addr="127.0.0.1",
252-
port=redis_port)]
253-
plasma_manager_command2 = [plasma_manager_executable,
254-
"-s", store_name2,
255-
"-m", manager_name2,
256-
"-h", "127.0.0.1",
257-
"-p", str(self.port2),
258-
"-r", "{addr}:{port}".format(addr="127.0.0.1",
259-
port=redis_port)]
260-
261-
if USE_VALGRIND:
262-
self.p4 = subprocess.Popen(["valgrind", "--track-origins=yes", "--leak-check=full", "--show-leak-kinds=all", "--error-exitcode=1"] + plasma_manager_command1)
263-
self.p5 = subprocess.Popen(["valgrind", "--track-origins=yes", "--leak-check=full", "--show-leak-kinds=all", "--error-exitcode=1"] + plasma_manager_command2)
264-
else:
265-
self.p4 = subprocess.Popen(plasma_manager_command1)
266-
self.p5 = subprocess.Popen(plasma_manager_command2)
269+
self.p4, self.port1 = start_plasma_manager(store_name1, manager_name1, redis_port, USE_VALGRIND)
270+
self.p5, self.port2 = start_plasma_manager(store_name2, manager_name2, redis_port, USE_VALGRIND)
267271

268272
# Connect two PlasmaClients.
269273
self.client1 = plasma.PlasmaClient(store_name1, manager_name1)

0 commit comments

Comments
 (0)