NationalSecurityAgency/ghidra · error · RuntimeError

Already connected

Error message

Already connected

What it means

Raised by State.require_no_client in the Ghidra LLDB agent when STATE.client is already set — i.e. a connection to Ghidra already exists. Commands that start a fresh connection (the connect command itself, at commands.py:278 and :329) call require_no_client to prevent stacking two connections; an existing client is rejected with RuntimeError.

Source

Thrown at Ghidra/Debug/Debugger-agent-lldb/src/main/py/src/ghidralldb/commands.py:103

    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 is not 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 is not 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

  1. Run the disconnect command (ghidra_trace_disconnect) before connecting again.
  2. Guard scripts: if STATE.client is not None, disconnect first.
  3. Catch RuntimeError in command wrappers and hint 'already connected; run ghidra_trace_disconnect first'.
  4. Ensure reset_client/disconnect is called on script exit or on connection error.

Example fix

// before
STATE.require_no_client()
client = Client(host, port)
// after
if STATE.client is not None:
    STATE.require_client().close()
    STATE.reset_client()
STATE.require_no_client()
client = Client(host, port)
Defensive patterns

Strategy: validation

Validate before calling

if STATE.client is not None:
    STATE.require_client().close()
    STATE.reset_client()
STATE.require_no_client()
client = Client(host, port)

Type guard

def is_disconnected() -> bool:
    return STATE.client is None

Try / catch

try:
    STATE.require_no_client()
except RuntimeError:
    print("Already connected; run ghidra_trace_disconnect first")
    return

Prevention

When it happens

Trigger: Running the connect command (ghidra_trace_connect) a second time without first disconnecting. The connect command asserts require_no_client before opening a new Client.

Common situations: User runs 'ghidra_trace_connect' twice; previous connection was not cleaned up (disconnect not run); script reconnects without teardown.

Related errors


AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14). Data as JSON: /api/errors/5750a91f3a24b8c5. Report an issue: GitHub.