Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when fcgi-program socket is already bound #1568

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions supervisor/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,15 @@ def payload(self):
class ProcessGroupAddedEvent(ProcessGroupEvent):
pass

class AddProcessGroupFailedEvent(ProcessGroupEvent):
def __init__(self, group, err = None):
super().__init__(group)
self.err = err

def payload(self):
payload = super().payload()
return payload+'error:%s\n' % self.err

class ProcessGroupRemovedEvent(ProcessGroupEvent):
pass

Expand Down
7 changes: 6 additions & 1 deletion supervisor/supervisord.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,12 @@ def add_process_group(self, config):
name = config.name
if name not in self.process_groups:
config.after_setuid()
self.process_groups[name] = config.make_group()
try:
self.process_groups[name] = config.make_group()
except BaseException as why:
self.options.logger.warn('Unable to add group %s: %s' % (name, why))
events.notify(events.AddProcessGroupFailedEvent(name, why))
return False
events.notify(events.ProcessGroupAddedEvent(name))
return True
return False
Expand Down
16 changes: 16 additions & 0 deletions supervisor/tests/test_supervisord.py
Original file line number Diff line number Diff line change
Expand Up @@ -834,3 +834,19 @@ def callback(event):
self.assertEqual(supervisord.ticks[3600], 3600)
self.assertEqual(len(L), 6)
self.assertEqual(L[-1].__class__, events.Tick3600Event)

def test_add_failing_process_group_wont_crush(self):
options = DummyOptions()
supervisord = self._makeOne(options)

pconfig = DummyPConfig(options, 'process1', '/bin/foo', '/tmp')
group = DummyPGroupConfig(options, 'group1', pconfigs=[pconfig])
def throw():
raise Exception()
group.make_group = throw

# set up supervisord with an active configuration of group1 and group2
supervisord.options.process_group_configs = [group]
self.assertFalse(supervisord.add_process_group(group))
self.assertTrue(not supervisord.process_groups)
self.assertTrue(str(options.logger.data[0]).startswith('Unable to add group'))