Skip to content

Commit 1fbdd40

Browse files
committed
mark_process_dead: avoid error with bad env
When the multiprocess environemnt is not properly set-up (missing environment variable) and mark_process_dead is called, the method raises an error on path.join() because the path is None which may be problematic This commit simply ignores the cleanup when the variable is not present
1 parent 39d2360 commit 1fbdd40

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

prometheus_client/multiprocess.py

+5
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,11 @@ def mark_process_dead(pid, path=None):
156156
"""Do bookkeeping for when one process dies in a multi-process setup."""
157157
if path is None:
158158
path = os.environ.get('PROMETHEUS_MULTIPROC_DIR', os.environ.get('prometheus_multiproc_dir'))
159+
160+
if path is None:
161+
# Avoid error when environment is not correctly set-up
162+
return
163+
159164
for f in glob.glob(os.path.join(path, f'gauge_livesum_{pid}.db')):
160165
os.remove(f)
161166
for f in glob.glob(os.path.join(path, f'gauge_liveall_{pid}.db')):

tests/test_multiprocess.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def _value_class(self):
6060
return
6161

6262
def tearDown(self):
63-
del os.environ['PROMETHEUS_MULTIPROC_DIR']
63+
os.environ.pop('PROMETHEUS_MULTIPROC_DIR', None)
6464
shutil.rmtree(self.tempdir)
6565
values.ValueClass = MutexValue
6666

@@ -303,6 +303,11 @@ def test_missing_gauge_file_during_merge(self):
303303
os.path.join(self.tempdir, 'gauge_livesum_9999999.db'),
304304
]))
305305

306+
def test_mark_dead_no_env(self):
307+
del os.environ['PROMETHEUS_MULTIPROC_DIR']
308+
309+
mark_process_dead(123)
310+
306311

307312
class TestMmapedDict(unittest.TestCase):
308313
def setUp(self):

0 commit comments

Comments
 (0)