fix: Deadlock in instances_use when port not yet registered
Some checks failed
Build Ghidra Plugin / build (push) Has been cancelled

instances_use held _instances_lock while calling register_instance,
which also acquires the same lock — non-reentrant Lock = hang forever.

- Release lock before calling register_instance (avoids blocking
  other threads during the HTTP health check too)
- Upgrade Lock → RLock as safety net for any other reentrant paths
This commit is contained in:
Ryan Malloy 2026-01-30 19:25:25 -07:00
parent 290252c0db
commit 1b42ab251e
2 changed files with 8 additions and 7 deletions

View File

@ -4,7 +4,7 @@ Provides shared state and utilities for all domain mixins.
"""
import time
from threading import Lock
from threading import RLock
from typing import Any, Dict, Optional
from fastmcp import Context
@ -25,7 +25,7 @@ class GhydraMixinBase(MCPMixin):
# Shared state across all mixins
_instances: Dict[int, Dict[str, Any]] = {}
_instances_lock = Lock()
_instances_lock = RLock()
_current_port: Optional[int] = None
def __init__(self):

View File

@ -168,11 +168,12 @@ class InstancesMixin(GhydraMixinBase):
Confirmation message with instance details
"""
with self._instances_lock:
if port not in self._instances:
# Try to register it first
result = self.register_instance(port)
if "Failed" in result or "Error" in result:
return result
needs_register = port not in self._instances
if needs_register:
result = self.register_instance(port)
if "Failed" in result or "Error" in result:
return result
self.set_current_port(port)