Skip to content

Conversation

@yumosx
Copy link

@yumosx yumosx commented Jan 16, 2026

Description

Add caching mechanism for file descriptor count to avoid frequent lsof command execution. Implement periodic updates with configurable interval to maintain accuracy while preventing resource leaks. Add tests to verify caching behavior and update intervals.

Fixes: continue cli leaking lsof execs · Issue #9422 · continuedev/continue

AI Code Review

  • Team members only: AI review runs automatically when PR is opened or marked ready for review
  • Team members can also trigger a review by commenting @continue-review

Checklist

  • I've read the contributing guide
  • The relevant docs, if any, have been updated or created
  • The relevant tests, if any, have been updated or created

Screen recording or screenshot

[ When applicable, please include a short screen recording or screenshot - this makes it much easier for us as contributors to review and understand your changes. See this PR as a good example. ]

Tests

  1. Check which process is running the target script
    Run the following command to find the process:

    ps aux | grep "node cn.js --verbose"
    
  2. Observe the output and note the PID

    root     13448  0.9  1.8 22474448 299940 pts/2 Sl+  02:09   0:13 node cn.js --verbose
    

    → The process ID (PID) is 13448.

  3. Create a simple monitoring script to watch lsof behavior on that PID
    Create a bash script (for example monitor.sh) with the following content:

    #!/bin/bash
    echo "Starting monitoring..."
    while true; do
        if pgrep -f "lsof -p 13448" >/dev/null 2>&1; then
            date '+%H:%M:%S.%N - lsof executing'
        fi
    done
  4. Run the monitoring script
    Execute it in the background or in another terminal:

    bash monitor.sh
    

    (or ./monitor.sh after chmod +x monitor.sh)

  5. Observe the result
    You will see frequent/tight timestamps whenever the command lsof -p 13448 is actively running:

    02:39:10.970678309 - lsof executing
    02:39:10.972740008 - lsof executing
    02:39:10.974828662 - lsof executing
    02:39:10.977207083 - lsof executing
    02:39:15.941282960 - lsof executing
    ...
    

@yumosx yumosx requested a review from a team as a code owner January 16, 2026 03:43
@yumosx yumosx requested review from RomneyDa and removed request for a team January 16, 2026 03:43
@continue
Copy link
Contributor

continue bot commented Jan 16, 2026

All Green - Keep your PRs mergeable

Learn more

All Green is an AI agent that automatically:

✅ Addresses code review comments

✅ Fixes failing CI checks

✅ Resolves merge conflicts


Unsubscribe from All Green comments

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jan 16, 2026
@yumosx yumosx changed the title fix(resource-monitoring): prevent file lsof leak fix(resource-monitoring): fix lsof file descriptor leak Jan 16, 2026
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

3 issues found across 2 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="extensions/cli/src/services/ResourceMonitoringService.test.ts">

<violation number="1" location="extensions/cli/src/services/ResourceMonitoringService.test.ts:124">
P2: Leak regression test is ineffective: it performs no assertion when lsof is unavailable and doesn’t verify lsof call frequency, so a leak can slip through undetected.</violation>

<violation number="2" location="extensions/cli/src/services/ResourceMonitoringService.test.ts:137">
P2: FD refresh interval test never exercises refresh and has no effective assertion; it always passes even if refresh doesn’t occur.</violation>
</file>

<file name="extensions/cli/src/services/ResourceMonitoringService.ts">

<violation number="1" location="extensions/cli/src/services/ResourceMonitoringService.ts:134">
P1: updateFileDescriptorCount() runs on every getCurrentResourceUsage call, spawning lsof every second despite intended 5s throttling</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@yumosx
Copy link
Author

yumosx commented Jan 19, 2026

tests for this pr:

  1. Check which process is running the target script
    Run the following command to find the process:

    ps aux | grep "node cn.js --verbose"
    
  2. Observe the output and note the PID

    root     13448  0.9  1.8 22474448 299940 pts/2 Sl+  02:09   0:13 node cn.js --verbose
    

    → The process ID (PID) is 13448.

  3. Create a simple monitoring script to watch lsof behavior on that PID
    Create a bash script (for example monitor.sh) with the following content:

    #!/bin/bash
    echo "Starting monitoring..."
    while true; do
        if pgrep -f "lsof -p 13448" >/dev/null 2>&1; then
            date '+%H:%M:%S.%N - lsof executing'
        fi
    done
  4. Run the monitoring script
    Execute it in the background or in another terminal:

    bash monitor.sh
    

    (or ./monitor.sh after chmod +x monitor.sh)

  5. Observe the result
    You will see frequent/tight timestamps whenever the command lsof -p 13448 is actively running:

    02:39:10.970678309 - lsof executing
    02:39:10.972740008 - lsof executing
    02:39:10.974828662 - lsof executing
    02:39:10.977207083 - lsof executing
    02:39:15.941282960 - lsof executing
    ...
    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

continue cli leaking lsof execs

1 participant