Skip to content

empty-catch: sdks/python/pmxt/server_manager.py:366 — except (json.JSONDecodeError, OSError): return False masks corrupted lock file in is_server_alive #2139

Description

@realfishsam

Violation

        try:
            # Read lock file
            lock_data = json.loads(self.lock_path.read_text())
            pid = lock_data.get('pid')
            port = lock_data.get('port', self.DEFAULT_PORT)

            if not pid:
                return False

            # Check if process exists (cross-platform)
            if not self._is_process_running(pid):
                # Process doesn't exist, remove stale lock file
                self._remove_stale_lock()
                return False

            # Quick health check to verify server is responsive
            return self._check_health(port, timeout=1)

        except (json.JSONDecodeError, OSError):
            return False

Location

sdks/python/pmxt/server_manager.py:348-367 (in is_server_alive)

Why It Matters

is_server_alive is the universal liveness check used to decide whether a new sidecar needs to be spawned. If the lock file is corrupted (JSONDecodeError) or unreadable (OSError), the method silently returns False with no logging, indistinguishable from the legitimate "server not running" case. A corrupted lock file left behind by a crashed process will cause every caller to believe no server exists and spawn a new one (or worse, mask a real filesystem permission problem) with no diagnostic trail explaining why the existing lock file was ignored.

Suggested Fix

Log the swallowed exception before returning False:

        except (json.JSONDecodeError, OSError) as exc:
            logger.debug("Failed to read lock file in is_server_alive", {"error": str(exc)})
            return False

Found by automated code hygiene audit

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions