Skip to content

fix: clean pending transport requests and add leak-check xtask probes#690

Merged
psteinroe merged 5 commits intomainfrom
fix/transport-pending-leak-and-xtask-probes
Feb 27, 2026
Merged

fix: clean pending transport requests and add leak-check xtask probes#690
psteinroe merged 5 commits intomainfrom
fix/transport-pending-leak-and-xtask-probes

Conversation

@psteinroe
Copy link
Copy Markdown
Collaborator

Summary

Fixes retained-memory growth in SocketTransport::request by ensuring pending request entries are removed on all error paths (serialization/send/channel-close/timeout), and by only inserting entries after successful request serialization.

This PR also adds a reusable leak-check workflow via xtask:

  • --probe lsp: macOS leaks check for LSP open/change/close churn
  • --probe cli-timeout: retained-memory growth probe for timeout/channel-close scenarios
  • --probe both: runs both probes sequentially

Leak root cause

pending_requests entries were inserted before serialization/send/wait finished and were not always removed when requests failed early. Repeated failing requests caused unbounded map growth and RSS growth.

Why this fixes it

  • serialize first, then insert into pending_requests
  • on any async request error, remove the request id from pending_requests before returning

Test plan

  • Added pgls_cli regression tests:
    • request_does_not_retain_pending_entries_when_serialization_fails
    • request_does_not_retain_pending_entries_on_timeout_or_channel_close
  • Ran:
    • cargo test -p pgls_cli request_does_not_retain_pending_entries_when_serialization_fails
    • cargo test -p pgls_cli request_does_not_retain_pending_entries_on_timeout_or_channel_close
    • cargo run -p xtask -- leak-check --probe cli-timeout --iterations 200000
    • cargo run -p xtask -- leak-check --probe lsp --iterations 20000 --pause-ms 1

- Fix taplo formatting by aligning dependency keys in xtask/Cargo.toml
- Gate UnixStream and related imports/functions with #[cfg(unix)] to fix
  Windows compilation
- Use inline format args in bail! macro to satisfy clippy

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@juleswritescode juleswritescode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only one major concern: socket timeouts in longer-running cli integration tests

Comment thread xtask/src/leak_check.rs Outdated
Comment thread xtask/src/leak_check.rs
Comment thread xtask/src/leak_check.rs Outdated
Comment thread crates/pgls_cli/src/service/mod.rs Outdated
psteinroe and others added 3 commits February 27, 2026 14:43
- Make REQUEST_TIMEOUT configurable via open_with_timeout() instead of
  #[cfg(test)] hack
- Check that `leaks` tool is installed before running probes
- Replace custom json_escape with serde_json::json! macro
- Use 2ms timeout in leak-check xtask (no point waiting on a dropped stream)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Comment thread xtask/src/leak_check.rs
}

fn send_lsp_message(stdin: &mut ChildStdin, payload: &str) -> anyhow::Result<()> {
fn send_lsp_json(stdin: &mut ChildStdin, value: Value) -> anyhow::Result<()> {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

schick!

@psteinroe psteinroe merged commit 3253db3 into main Feb 27, 2026
9 checks passed
@psteinroe psteinroe deleted the fix/transport-pending-leak-and-xtask-probes branch February 27, 2026 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants