NationalSecurityAgency/ghidra · error · RuntimeError
Already connected
Error message
Already connected
What it means
Raised by State.require_no_client when STATE.client is not None (already connected). This guard prevents duplicate connections; ghidra_trace_connect and ghidra_trace_listen both call require_no_client to ensure a connection does not already exist before opening a new one.
Source
Thrown at Ghidra/Debug/Debugger-agent-x64dbg/src/main/py/src/ghidraxdbg/commands.py:123
def require_rm(self) -> arch.DefaultRegisterMapper:
if self.register_mapper is None:
raise RuntimeError("No register mapper")
return self.register_mapper
class State(object):
def __init__(self) -> None:
self.reset_client()
def require_client(self) -> Client:
if self.client is None:
raise RuntimeError("Not connected")
return self.client
def require_no_client(self) -> None:
if self.client != None:
raise RuntimeError("Already connected")
def reset_client(self) -> None:
self.client: Optional[Client] = None
self.reset_trace()
def require_trace(self) -> Trace[Extra]:
if self.trace is None:
raise RuntimeError("No trace active")
return self.trace
def require_no_trace(self) -> None:
if self.trace != None:
raise RuntimeError("Trace already started")
def reset_trace(self) -> None:
self.trace: Optional[Trace[Extra]] = None
util.set_convenience_variable('_ghidra_tracing', "false")
self.reset_tx()View on GitHub (pinned to d5f144c24d)
Solutions
- Call 'ghidra_trace_disconnect' before establishing a new connection.
- Check STATE.client is None before calling ghidra_trace_connect or ghidra_trace_listen.
- Add STATE.reset_client() in error recovery paths to clean up stale connections.
Example fix
# before: connect while already connected
ghidra_trace_connect('127.0.0.1:12345') # first connection
ghidra_trace_connect('127.0.0.1:9999') # Already connected
# after: disconnect first
if STATE.client is not None:
ghidra_trace_disconnect()
ghidra_trace_connect('127.0.0.1:9999') Defensive patterns
Strategy: validation
Validate before calling
if STATE.client is not None:
raise RuntimeError("Already connected; run 'ghidra trace disconnect' first") Type guard
def is_not_connected() -> bool:
return STATE.client is None Try / catch
try:
ghidra_trace_connect(address)
except RuntimeError:
if 'Already connected' in str(e):
ghidra_trace_disconnect()
ghidra_trace_connect(address)
else:
raise Prevention
- Call 'ghidra trace disconnect' before establishing a new connection.
- Check STATE.client is None before calling ghidra_trace_connect or ghidra_trace_listen.
- Use STATE.reset_client() in cleanup paths to clear stale connections.
When it happens
Trigger: ghidra_trace_connect or ghidra_trace_listen is called when STATE.client already holds an active Client. The require_no_client guard fires because a connection already exists.
Common situations: User ran 'ghidra trace connect' twice without disconnecting in between. A previous connection was not properly reset (e.g. the script re-ran without cleanup). The user switched from connect to listen mode without disconnecting first.
Related errors
AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14).
Data as JSON: /api/errors/c1a52ea627039389.
Report an issue: GitHub.