Repository navigation
Conversation
…and sync loss When GDB emits an MI line exceeding the 16 MiB protocol limit, protocol failure marks MI synchronization lost. Attempting inferior detachment over the desynchronized MI transport throws and previously aborted process termination, leaving GDB and its inferior running indefinitely as zombie processes. Support forced termination in stopOwnedDebuggerProcess, clear line buffers on overflow, pass force: true when MI sync is lost or during close, and surface informative top-level guidance.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
[Medium impact] The changed cleanup path is limited to GDB sessions that lose MI synchronization. The PR needs a fix before merging because MI failure during detach can still leave the owned GDB process running. FindingsFix with agent prompt### Issue 1
src/gdb/GdbSessionManager.ts:1942-1945
`force` is chosen only when a stop starts. If `closeAll()` loses MI sync while `#detachInferior()` awaits a reply, that stop is already running with `force: false`. An oversized reply returns `incomplete` before `SIGTERM`. A command timeout calls `#stopDebuggerOnly()` again but gets the same non-forced promise. GDB stays alive until another cleanup call.
Once the first attempt settles, retry with force if MI synchronization was lost during detachment.
### Issue 2
src/gdb/GdbSessionManager.ts:1920
After successful forced shutdown, `#stopAfterProtocolFailure()` leaves the session in `#sessions`, but this advice says it was closed and tells the caller only to start another one. `start()` still counts that entry against `REA_DEBUGGER_MAX_SESSIONS`. Following the advice repeatedly fills the available slots; with a one-session limit, the first replacement already fails.
Remove the finished entry, or tell the caller to run `close_gdb_session` with this `session_id` before starting a replacement.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.SummaryAdds forced shutdown of the owned GDB process after MI failure, clears overflow buffers, and preserves cleanup retries.
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Stop requested] --> B{MI already failed?}
B -- Yes --> C[Terminate owned GDB]
B -- No --> D[Verify inferior]
D -- Confirmed --> C
D -- Sync lost --> E[Cleanup incomplete]
E --> F[Another cleanup call]
F --> C
C --> G{Output closed?}
G -- Yes --> H[Release supervisor]
G -- No --> I[Retain owner for retry]
I --> J[Forced POSIX stop unrefs output]
Reviews (4) · Last reviewed commit: "Merge remote-tracking branch 'upstream/m..." · Reviewed by Greptile |
|
I tested this PR at
This PR:
One gap remains. Each command sent to the closed session afterwards returns a generic I also tested #8029, which keeps the session usable by dropping the oversized stream record. The two approaches look complementary: #8029 for stream records, and this PR's forced stop for protocol failures that still close the session. |
|
Thanks @Rinkia for testing this with GNU gdb 15.1 and verifying that the lingering GDB and inferior processes are cleanly removed! Regarding retaining the stop reason on subsequent commands and adding a |
…ow-teardown # Conflicts: # src/gdb/GdbSessionManager.ts
| this.#stopProcess(session, "GDB", { | ||
| platform: this.#platform, | ||
| force: options?.force ?? session.protocolError !== undefined, | ||
| }), |
There was a problem hiding this comment.
force is chosen only when a stop starts. If closeAll() loses MI sync while #detachInferior() awaits a reply, that stop is already running with force: false. An oversized reply returns incomplete before SIGTERM. A command timeout calls #stopDebuggerOnly() again but gets the same non-forced promise. GDB stays alive until another cleanup call.
Once the first attempt settles, retry with force if MI synchronization was lost during detachment.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/gdb/GdbSessionManager.ts
Line: 1942-1945
Comment:
**Shutdown leaves GDB running**
`force` is chosen only when a stop starts. If `closeAll()` loses MI sync while `#detachInferior()` awaits a reply, that stop is already running with `force: false`. An oversized reply returns `incomplete` before `SIGTERM`. A command timeout calls `#stopDebuggerOnly()` again but gets the same non-forced promise. GDB stays alive until another cleanup call.
Once the first attempt settles, retry with force if MI synchronization was lost during detachment.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| remediationAction: | ||
| stopped.status === "incomplete" | ||
| ? `The GDB session protocol failed and cleanup could not be confirmed: ${stopped.reason}. Retry close_gdb_session with session_id "${session.id}".` | ||
| : "The GDB session protocol failed and the session was closed. Start a new GDB session to continue.", |
There was a problem hiding this comment.
After successful forced shutdown, #stopAfterProtocolFailure() leaves the session in #sessions, but this advice says it was closed and tells the caller only to start another one. start() still counts that entry against REA_DEBUGGER_MAX_SESSIONS. Following the advice repeatedly fills the available slots; with a one-session limit, the first replacement already fails.
Remove the finished entry, or tell the caller to run close_gdb_session with this session_id before starting a replacement.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/gdb/GdbSessionManager.ts
Line: 1920
Comment:
**Recovery fills session slots**
After successful forced shutdown, `#stopAfterProtocolFailure()` leaves the session in `#sessions`, but this advice says it was closed and tells the caller only to start another one. `start()` still counts that entry against `REA_DEBUGGER_MAX_SESSIONS`. Following the advice repeatedly fills the available slots; with a one-session limit, the first replacement already fails.
Remove the finished entry, or tell the caller to run `close_gdb_session` with this `session_id` before starting a replacement.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Summary
Fixes #8023.
When GDB emits an MI line exceeding the 16 MiB protocol limit, REA fails the protocol and marks MI synchronization lost. Attempting inferior detachment over the desynchronized MI transport throws and previously aborted process termination in
stopOwnedDebuggerProcess, leaving GDB and its inferior processes alive indefinitely as zombies with no way to detach, kill, or close them.This change:
force?: booleanoption tostopOwnedDebuggerProcessto terminate the owned debugger process immediately with SIGTERM/SIGKILL when detachment cannot be verified or MI state is desynchronized.bufferChunks,bufferTail,bufferBytes) immediately on overflow inGdbSessionManagerto release retained memory.close_gdb_sessionof a failed session, while preserving detach verification on normal sessions.forcedShutdownsto permit subsequent close calls on already-exited sessions without failing on inferior verification.docs/reverse-engineering-tools.mdto document direct termination and unknown inferior disposition on protocol failure.Problem and expected behavior
When a GDB console command (such as printing an unbounded data structure with
set print elements 0) produces a single MI record over 16 MiB:detachInferior(), which threw"GDB MI state is not synchronized; inferior state is unknown."stopOwnedDebuggerProcesscaught the rejection and returned early (status: "incomplete"), failing to send SIGTERM/SIGKILL.Expected behavior:
When closing or tearing down a desynchronized or failed debugger session, the owned debugger process must be terminated directly with SIGTERM/SIGKILL, output streams released on timeout, and subsequent close calls allowed to complete cleanly.
Change and scope
src/process/ownedDebuggerSession.ts:force?: booleanoption tostopOwnedDebuggerProcess.forcedShutdownsso subsequent close calls on already-exited sessions succeed without inferior verification.src/gdb/GdbSessionManager.ts:#receivewhenlineBytes > MAX_MI_LINE_BYTES.{ platform: this.#platform, force: options?.force ?? session.protocolError !== undefined }in#stopDebuggerOnly.session.protocolError !== undefinedso normal sessions still verify detachment.userMessageandremediationActiononAnalysisCapabilityUnavailableErrorin#stopAfterProtocolFailure, distinguishing confirmed stops from incomplete ones.docs/reverse-engineering-tools.md:tests/boundary/process/ownedDebuggerSession.test.ts:stopOwnedDebuggerProcesswithforce: trueimmediately terminates the debugger process with SIGTERM without callingdetachInferior.tests/boundary/providers/GdbSessionManagerCoverage.test.ts:Contract and boundary impact
stopOwnedDebuggerProcessprocess termination gate;GdbSessionManagerprotocol failure teardown.close_gdb_sessionreliably cleans up and terminates the session when MI sync is lost.Expected effects:
Evidence and regression coverage
tests/boundary/process/ownedDebuggerSession.test.ts: tests for forced SIGTERM, stream unreferencing on timeout, and exited session close without inferior checks.tests/boundary/providers/GdbSessionManagerCoverage.test.ts: tests for direct termination on sync loss, line overflow teardown, and close retry.stopOwnedDebuggerProcessreturned{ status: "incomplete" }and did not invokeprocess.kill()whendetachInferiorrejected.close_gdb_sessionreturns cleanly rather than failing withcleanup_incomplete, and GDB process terminates.For evidence-bearing changes:
Validation performed
npm run compile- clean build.npm run check:fast- full turbo typecheck & lint passed (2 successful).npm run verify:module-boundaries- checked 3429 source files successfully.npm run verify:test-discovery- discovered all 2865 test files exactly once.npx vitest run tests/boundary/process/ownedDebuggerSession.test.ts- 39 passed, 4 skipped.npx vitest run tests/boundary/providers/GdbSessionManagerCoverage.test.ts -t "sync loss|overflow|retains ownership without signaling"- 5 passed.Compatibility, safety, and release
Author readiness
Human owner: @highmachs
Before merge
type(scope): outcome.