NationalSecurityAgency/ghidra · warning · RuntimeError
Already connected
Error message
Already connected
What it means
Thrown by State.require_no_client() when a client connection already exists and a second connection is attempted. This guard prevents establishing multiple simultaneous connections to the trace server. The RuntimeError is raised if STATE.client is not None when require_no_client is called — typically at the start of ghidra_trace_connect.
Source
Thrown at Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/commands.py:126
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 calling ghidra_trace_connect() again.
- Check connection state: call require_client() to see if already connected before connecting.
- In scripts, always pair connect/disconnect in try/finally blocks.
- If the connection is stale, disconnect and reconnect cleanly.
Example fix
# Before: double connect
# ghidra_trace_connect('127.0.0.1:12345')
# ghidra_trace_connect('127.0.0.1:12345') # throws
#
# After:
# ghidra_trace_disconnect()
# ghidra_trace_connect('127.0.0.1:12345') Defensive patterns
Strategy: validation
Validate before calling
# Before connecting, check if already connected:
if STATE.client is not None:
ghidra_trace_disconnect()
ghidra_trace_connect(address) Type guard
def is_already_connected(state) -> bool:
return state.client is not None Try / catch
try:
ghidra_trace_connect(address)
except RuntimeError as e:
if str(e) == 'Already connected':
ghidra_trace_disconnect()
ghidra_trace_connect(address)
else:
raise Prevention
- Always disconnect before reconnecting to avoid double-connect errors.
- Use try/finally blocks to ensure clean disconnect on errors.
- Check connection state before calling connect.
- Idempotent scripts should disconnect first or check state.
When it happens
Trigger: STATE.require_no_client() is called at the beginning of ghidra_trace_connect, but STATE.client is already set from a previous successful connection. Happens when the user calls ghidra_trace_connect twice without disconnecting first, or when a script reconnects without calling ghidra_trace_disconnect.
Common situations: The user runs the connect command again without first disconnecting. A script loops and reconnects without cleanup. The previous connection is stale but was never formally closed.
Related errors
- Not connected
- Already connected
- Address {address} is not in process {proc}
- Invalid byte_order: {}
- Cannot convert {}'s value: '{}', type: '{}'
AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14).
Data as JSON: /api/errors/ba04749e4ec1e71a.
Report an issue: GitHub.