fix: isolate subprocess stdin and decouple startup to prevent MCP stdio deadlocks

- Set stdin=subprocess.DEVNULL across runtime, client, and utility subprocess calls to avoid hijacking the parent process's stdin.
- Run awake service initialization asynchronously on a daemon thread in MCP server startup.
- Redirect logger header printing to stderr to ensure stdio JSON-RPC purity.
- Add unit and lifecycle tests for MCP stdio protocol handshake and stdin isolation.
This commit is contained in:
somew1nd committed 2026-08-26 23:26:10 -07:00
1 parent 8fdecf23d7
commit e984d17635
12 files changed
+237 -13

No files matched your search

+3 -1
View File
@@ -99,6 +99,7 @@ def get_connected_devices(adb_path: str | None = None) -> list[str]:
try:
res = subprocess.run(
[adb, "devices"],
stdin=subprocess.DEVNULL,
capture_output=True,
text=True,
timeout=5,
@@ -137,7 +138,7 @@ def ensure_emulator(
if not emu_exe or not os.path.exists(emu_exe):
return False
popen_kwargs = {"stdout": subprocess.DEVNULL, "stderr": subprocess.DEVNULL}
popen_kwargs = {"stdin": subprocess.DEVNULL, "stdout": subprocess.DEVNULL, "stderr": subprocess.DEVNULL}
if sys.platform == "win32":
popen_kwargs["creationflags"] = (
subprocess.CREATE_NEW_PROCESS_GROUP | subprocess.DETACHED_PROCESS # type: ignore[attr-defined]
@@ -158,6 +159,7 @@ def ensure_emulator(
try:
res = subprocess.run(
[adb, "-s", "emulator-5554", "shell", "getprop", "sys.boot_completed"],
stdin=subprocess.DEVNULL,
capture_output=True,
text=True,
timeout=3,
+1
View File
@@ -49,6 +49,7 @@ def resolve_python_executable(project_root: str | None = None) -> str:
def get_detached_process_kwargs() -> dict[str, Any]:
"""Returns kwargs for subprocess.Popen to run a fully detached background process cross-platform."""
kwargs: dict[str, Any] = {
"stdin": subprocess.DEVNULL,
"stdout": subprocess.DEVNULL,
"stderr": subprocess.DEVNULL,
}