Skip to content

Commit 5b1f3dc

Browse files
committed
Guard against attempt to spawn process in UNKNOWN state
1 parent 3c66606 commit 5b1f3dc

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

supervisor/rpcinterface.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,10 @@ def startProcess(self, name, wait=True):
299299
if process.get_state() in RUNNING_STATES:
300300
raise RPCError(Faults.ALREADY_STARTED, name)
301301

302+
if process.get_state() == ProcessStates.UNKNOWN:
303+
raise RPCError(Faults.FAILED,
304+
"%s is in an unknown process state" % name)
305+
302306
process.spawn()
303307

304308
# We call reap() in order to more quickly obtain the side effects of

supervisor/tests/test_rpcinterfaces.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,6 @@ def test_removeProcessGroup_still_running(self):
311311
self._assertRPCError(xmlrpc.Faults.STILL_RUNNING,
312312
interface.removeProcessGroup, 'group1')
313313

314-
315314
def test_startProcess_already_started(self):
316315
from supervisor import xmlrpc
317316
options = DummyOptions()
@@ -324,6 +323,22 @@ def test_startProcess_already_started(self):
324323
interface.startProcess, 'foo'
325324
)
326325

326+
def test_startProcess_unknown_state(self):
327+
from supervisor import xmlrpc
328+
from supervisor.states import ProcessStates
329+
options = DummyOptions()
330+
pconfig = DummyPConfig(options, 'foo', __file__, autostart=False)
331+
supervisord = PopulatedDummySupervisor(options, 'foo', pconfig)
332+
supervisord.set_procattr('foo', 'pid', 10)
333+
supervisord.set_procattr('foo', 'state', ProcessStates.UNKNOWN)
334+
interface = self._makeOne(supervisord)
335+
self._assertRPCError(
336+
xmlrpc.Faults.FAILED,
337+
interface.startProcess, 'foo'
338+
)
339+
process = supervisord.process_groups['foo'].processes['foo']
340+
self.assertEqual(process.spawned, False)
341+
327342
def test_startProcess_bad_group_name(self):
328343
options = DummyOptions()
329344
pconfig = DummyPConfig(options, 'foo', __file__, autostart=False)

0 commit comments

Comments
 (0)