fix: Deadlock in instances_use when port not yet registered
Some checks failed
Build Ghidra Plugin / build (push) Has been cancelled
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:
parent
290252c0db
commit
1b42ab251e
@ -4,7 +4,7 @@ Provides shared state and utilities for all domain mixins.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import time
|
import time
|
||||||
from threading import Lock
|
from threading import RLock
|
||||||
from typing import Any, Dict, Optional
|
from typing import Any, Dict, Optional
|
||||||
|
|
||||||
from fastmcp import Context
|
from fastmcp import Context
|
||||||
@ -25,7 +25,7 @@ class GhydraMixinBase(MCPMixin):
|
|||||||
|
|
||||||
# Shared state across all mixins
|
# Shared state across all mixins
|
||||||
_instances: Dict[int, Dict[str, Any]] = {}
|
_instances: Dict[int, Dict[str, Any]] = {}
|
||||||
_instances_lock = Lock()
|
_instances_lock = RLock()
|
||||||
_current_port: Optional[int] = None
|
_current_port: Optional[int] = None
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|||||||
@ -168,11 +168,12 @@ class InstancesMixin(GhydraMixinBase):
|
|||||||
Confirmation message with instance details
|
Confirmation message with instance details
|
||||||
"""
|
"""
|
||||||
with self._instances_lock:
|
with self._instances_lock:
|
||||||
if port not in self._instances:
|
needs_register = port not in self._instances
|
||||||
# Try to register it first
|
|
||||||
result = self.register_instance(port)
|
if needs_register:
|
||||||
if "Failed" in result or "Error" in result:
|
result = self.register_instance(port)
|
||||||
return result
|
if "Failed" in result or "Error" in result:
|
||||||
|
return result
|
||||||
|
|
||||||
self.set_current_port(port)
|
self.set_current_port(port)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user