Skip to content

Commit 773adb9

Browse files
authored
Avoid waiting on connection when server is dead (#187)
1 parent 09ced57 commit 773adb9

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

RLTest/redis_cluster.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def checkExitCode(self):
183183
return True
184184

185185
def isUp(self):
186-
return self.envIsUp or self.waitCluster()
186+
return self.envIsUp or self.envIsHealthy and self.waitCluster()
187187

188188
def isHealthy(self):
189189
return self.envIsHealthy

RLTest/redis_std.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,8 @@ def createCmdOSEnv(self, role):
245245
osenv["ASAN_OPTIONS"] = "{OPT}:log_path={DIR}".format(OPT=asan_options, DIR=san_log)
246246
return osenv
247247

248-
def waitForRedisToStart(self, con):
249-
wait_for_conn(con, retries=1000 if self.debugger else 200)
248+
def waitForRedisToStart(self, con, proc):
249+
wait_for_conn(con, proc, retries=1000 if self.debugger else 200)
250250
self._waitForAOFChild(con)
251251

252252
def getPid(self, role):
@@ -313,22 +313,30 @@ def startEnv(self, masters = True, slaves = True):
313313
print(Colors.Green("Redis master command: " + ' '.join(self.masterCmdArgs)))
314314
if masters and self.masterProcess is None:
315315
self.masterProcess = subprocess.Popen(args=self.masterCmdArgs, env=self.masterOSEnv, **options)
316-
con = self.getConnection()
317-
self.waitForRedisToStart(con)
316+
time.sleep(0.1)
317+
if self._isAlive(self.masterProcess):
318+
con = self.getConnection()
319+
self.waitForRedisToStart(con, self.masterProcess)
320+
else:
321+
self.masterProcess = None
318322
if self.useSlaves and slaves and self.slaveProcess is None:
319323
if self.verbose:
320324
print(Colors.Green("Redis slave command: " + ' '.join(self.slaveCmdArgs)))
321325
self.slaveProcess = subprocess.Popen(args=self.slaveCmdArgs, env=self.slaveOSEnv, **options)
322-
con = self.getSlaveConnection()
323-
self.waitForRedisToStart(con)
324-
self.envIsUp = True
326+
time.sleep(0.1)
327+
if self._isAlive(self.slaveProcess):
328+
con = self.getSlaveConnection()
329+
self.waitForRedisToStart(con, self.slaveProcess)
330+
else:
331+
self.slaveProcess = None
332+
333+
self.envIsUp = self.masterProcess is not None or self.slaveProcess is not None
325334
self.envIsHealthy = self.masterProcess is not None and (self.slaveProcess is not None if self.useSlaves else True)
326335

327336
def _isAlive(self, process):
328337
if not process:
329338
return False
330-
# Check if child process has terminated. Set and return returncode
331-
# attribute
339+
# check if child process has terminated
332340
if process.poll() is None:
333341
return True
334342
return False

RLTest/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
import redis
77
import itertools
88

9-
def wait_for_conn(conn, retries=20, command='PING', shouldBe=True):
9+
def wait_for_conn(conn, proc, retries=20, command='PING', shouldBe=True):
1010
"""Wait until a given Redis connection is ready"""
1111
err1 = ''
1212
while retries > 0:
13+
if proc.poll() is not None:
14+
raise Exception(f'Redis server is dead (pid={proc.pid})')
1315
try:
1416
if conn.execute_command(command) == shouldBe:
1517
return conn

0 commit comments

Comments
 (0)