From b6b17f3ac3526aaca124b08cee858c4f0a06ffe6 Mon Sep 17 00:00:00 2001 From: Robert Nishihara Date: Tue, 16 Aug 2016 17:42:45 -0700 Subject: [PATCH] Retry if plasma client fails to connect to plasma store. --- src/plasma_client.c | 15 +++++++++++++-- test/test.py | 2 -- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/plasma_client.c b/src/plasma_client.c index 86b49125d..d58f194c7 100644 --- a/src/plasma_client.c +++ b/src/plasma_client.c @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include "plasma.h" #include "fling.h" @@ -81,7 +81,18 @@ int plasma_store_connect(const char* socket_name) { memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; strncpy(addr.sun_path, socket_name, sizeof(addr.sun_path)-1); - if (connect(fd, (struct sockaddr*)&addr, sizeof(addr)) == -1) { + // Try to connect to the Plasma store. If unsuccessful, retry several times. + int connected_successfully = 0; + for (int num_attempts = 0; num_attempts < 50; ++num_attempts) { + if (connect(fd, (struct sockaddr*)&addr, sizeof(addr)) == 0) { + connected_successfully = 1; + break; + } + // Sleep for 100 milliseconds. + usleep(100000); + } + // If we could not connect to the Plasma store, exit. + if (!connected_successfully) { LOG_ERR("could not connect to store %s", socket_name); exit(-1); } diff --git a/test/test.py b/test/test.py index f70b9809f..6d4bee003 100644 --- a/test/test.py +++ b/test/test.py @@ -1,7 +1,6 @@ import os import subprocess import sys -import time import unittest import plasma @@ -12,7 +11,6 @@ class TestPlasmaAPI(unittest.TestCase): # Start Plasma. plasma_store_executable = os.path.join(os.path.abspath(os.path.dirname(__file__)), "../build/plasma_store") self.p = subprocess.Popen([plasma_store_executable, "-s", "/tmp/store"]) - time.sleep(0.1) # Connect to Plasma. self.plasma_client = plasma.PlasmaClient("/tmp/store")