Skip to content

Commit 8bc8a57

Browse files
committed
Return 404 response for missing log file. Closes Supervisor#1406
1 parent eabc2c5 commit 8bc8a57

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

CHANGES.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
4.3.0.dev0 (Next Release)
22
-------------------------
33

4+
- The web interface will now return a 404 Not Found response if a log file
5+
is missing. Previously, it would return 410 Gone. It was changed because
6+
410 is intended to mean that the condition is likely to be permanent. A
7+
log file missing is usually temporary, e.g. a process that was never started
8+
will not have a log file but will have one as soon as it is started.
9+
410
4.2.2 (2021-02-26)
511
------------------
612

supervisor/http.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -737,10 +737,11 @@ def handle_request(self, request):
737737
logfile = getattr(process.config, '%s_logfile' % channel, None)
738738

739739
if logfile is None or not os.path.exists(logfile):
740-
# XXX problematic: processes that don't start won't have a log
741-
# file and we probably don't want to go into fatal state if we try
742-
# to read the log of a process that did not start.
743-
request.error(410) # gone
740+
# we return 404 because no logfile is a temporary condition.
741+
# if the process has never been started, no logfile will exist
742+
# on disk. a logfile of None is also a temporay condition,
743+
# since the config file can be reloaded.
744+
request.error(404) # not found
744745
return
745746

746747
mtime = os.stat(logfile)[stat.ST_MTIME]
@@ -774,7 +775,10 @@ def handle_request(self, request):
774775
logfile = self.supervisord.options.logfile
775776

776777
if logfile is None or not os.path.exists(logfile):
777-
request.error(410) # gone
778+
# we return 404 because no logfile is a temporary condition.
779+
# even if a log file of None is configured, the config file
780+
# may be reloaded, and the new config may have a logfile.
781+
request.error(404) # not found
778782
return
779783

780784
mtime = os.stat(logfile)[stat.ST_MTIME]

supervisor/tests/test_http.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def test_handle_request_stdout_logfile_none(self):
4545
handler = self._makeOne(supervisord)
4646
request = DummyRequest('/logtail/process1', None, None, None)
4747
handler.handle_request(request)
48-
self.assertEqual(request._error, 410)
48+
self.assertEqual(request._error, 404)
4949

5050
def test_handle_request_stdout_logfile_missing(self):
5151
options = DummyOptions()
@@ -54,7 +54,7 @@ def test_handle_request_stdout_logfile_missing(self):
5454
handler = self._makeOne(supervisord)
5555
request = DummyRequest('/logtail/foo', None, None, None)
5656
handler.handle_request(request)
57-
self.assertEqual(request._error, 410)
57+
self.assertEqual(request._error, 404)
5858

5959
def test_handle_request(self):
6060
with tempfile.NamedTemporaryFile() as f:
@@ -84,15 +84,15 @@ def test_handle_request_stdout_logfile_none(self):
8484
handler = self._makeOne(supervisor)
8585
request = DummyRequest('/mainlogtail', None, None, None)
8686
handler.handle_request(request)
87-
self.assertEqual(request._error, 410)
87+
self.assertEqual(request._error, 404)
8888

8989
def test_handle_request_stdout_logfile_missing(self):
9090
supervisor = DummySupervisor()
9191
supervisor.options.logfile = '/not/there'
9292
request = DummyRequest('/mainlogtail', None, None, None)
9393
handler = self._makeOne(supervisor)
9494
handler.handle_request(request)
95-
self.assertEqual(request._error, 410)
95+
self.assertEqual(request._error, 404)
9696

9797
def test_handle_request(self):
9898
supervisor = DummySupervisor()

0 commit comments

Comments
 (0)