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

Improve exception handling for fcgi-program socket creation #1570

Open
wants to merge 3 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@
license='BSD-derived (http://www.repoze.org/LICENSE.txt)',
url='http://supervisord.org/',
project_urls={
'Changelog': 'http://supervisord.org/changes.html',
'Changelog': 'http://supervisord.org/changelog',
'Documentation': 'http://supervisord.org',
'Issue Tracker': 'https://github.com/Supervisor/supervisor',
},
description="A system for controlling process state under UNIX",
long_description=README + '\n\n' + CHANGES,
Expand Down
14 changes: 13 additions & 1 deletion supervisor/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,19 @@ def spawn(self):
"""
Overrides Subprocess.spawn() so we can hook in before it happens
"""
self.before_spawn()
try:
self.before_spawn()
except NotImplementedError:
raise
except BaseException as e:
if hasattr(self, 'group') and hasattr(self.group, 'socket_manager'):
self.record_spawnerr('Could not create FastCGI socket %s: %s' % (
self.group.socket_manager.config(), e))
else:
self.record_spawnerr(e.args[0])
self.change_state(ProcessStates.BACKOFF)
self.give_up()
return
pid = Subprocess.spawn(self)
if pid is None:
#Remove object reference to decrement the reference count on error
Expand Down
14 changes: 13 additions & 1 deletion supervisor/tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from supervisor.tests.base import DummyProcessGroup
from supervisor.tests.base import DummyFCGIProcessGroup

from supervisor.process import Subprocess
from supervisor.process import Subprocess, ProcessStates
from supervisor.options import BadCommand

class SubprocessTests(unittest.TestCase):
Expand Down Expand Up @@ -1799,6 +1799,18 @@ def test_before_spawn_gets_socket_ref(self):
instance.before_spawn()
self.assertFalse(instance.fcgi_sock is None)

def test_before_spawn_failure_sets_fatal_state(self):
options = DummyOptions()
config = DummyPConfig(options, 'good', '/good/filename', uid=1)
instance = self._makeOne(config)
instance.group = Mock()
socket_manager = Mock()
instance.group.attach_mock(socket_manager, 'socket_manager')
socket_manager.attach_mock(Mock(side_effect=Exception), 'get_socket')
self.assertEqual(instance.state, ProcessStates.STOPPED)
instance.spawn()
self.assertEqual(instance.state, ProcessStates.FATAL)

def test_after_finish_removes_socket_ref(self):
options = DummyOptions()
config = DummyPConfig(options, 'good', '/good/filename', uid=1)
Expand Down