fix: teardown --all now kills collector processes

The collector kept streaming stale container IDs after a redeploy,
causing new service logs to never reach decnet.log. Now _kill_api()
also matches and SIGTERMs any running decnet.cli collect process.
This commit is contained in:
2026-04-14 00:17:57 -04:00
parent 8335c5dc4c
commit c2f7622fbb
2 changed files with 11 additions and 2 deletions

View File

@@ -62,6 +62,10 @@ def _kill_api() -> None:
console.print(f"[yellow]Stopping DECNET Mutator Watcher (PID {_proc.info['pid']})...[/]") console.print(f"[yellow]Stopping DECNET Mutator Watcher (PID {_proc.info['pid']})...[/]")
os.kill(_proc.info['pid'], signal.SIGTERM) os.kill(_proc.info['pid'], signal.SIGTERM)
_killed = True _killed = True
elif "decnet.cli" in _cmd and "collect" in _cmd:
console.print(f"[yellow]Stopping DECNET Collector (PID {_proc.info['pid']})...[/]")
os.kill(_proc.info['pid'], signal.SIGTERM)
_killed = True
except (psutil.NoSuchProcess, psutil.AccessDenied): except (psutil.NoSuchProcess, psutil.AccessDenied):
continue continue

View File

@@ -337,9 +337,14 @@ class TestKillApi:
"pid": 222, "name": "python", "pid": 222, "name": "python",
"cmdline": ["python", "decnet.cli", "mutate", "--watch"], "cmdline": ["python", "decnet.cli", "mutate", "--watch"],
} }
mock_iter.return_value = [mock_uvicorn, mock_mutate] mock_collector = MagicMock()
mock_collector.info = {
"pid": 333, "name": "python",
"cmdline": ["python", "-m", "decnet.cli", "collect", "--log-file", "/tmp/decnet.log"],
}
mock_iter.return_value = [mock_uvicorn, mock_mutate, mock_collector]
_kill_api() _kill_api()
assert mock_kill.call_count == 2 assert mock_kill.call_count == 3
@patch("psutil.process_iter") @patch("psutil.process_iter")
def test_no_matching_processes(self, mock_iter): def test_no_matching_processes(self, mock_iter):