Skip to content

Fix: Prevent infinite polling when continue_execution called multiple times - #26

Open
Piotr Tylenda (pitylend) wants to merge 1 commit into
microsoft:mainfrom
pitylend:fix/infinite-polling-on-continue
Open

Fix: Prevent infinite polling when continue_execution called multiple times#26
Piotr Tylenda (pitylend) wants to merge 1 commit into
microsoft:mainfrom
pitylend:fix/infinite-polling-on-continue

Conversation

@pitylend

Copy link
Copy Markdown

Problem

When calling continue_execution while the debugger is already running (not paused at a breakpoint), the waitForStateChange method would poll indefinitely waiting for a state change that would never come. This caused the MCP tool to hang forever.

Reproduction Steps

  1. Start debug session with an attach configuration
  2. Set a breakpoint
  3. Trigger code path to hit breakpoint
  4. Call continue_execution - works fine
  5. Call continue_execution again - HANGS FOREVER

Root Cause

The early exit condition in waitForStateChange was:

if(beforeState.hasLocationInfo()&&!currentState.hasLocationInfo()&&afterState.sessionActive){returnfalse;// Keep polling}

This only handled the case where we HAD location info before continuing. When calling continue a second time:

  • beforeState already had NO location info (process was running)
  • The condition beforeState.hasLocationInfo() was false
  • So we never entered the early exit logic and polled forever

Solution

Added tracking of consecutive attempts where the process is running without location info:

if(!currentState.hasLocationInfo()&&currentState.sessionActive){runningWithoutLocationAttempts++;if(runningWithoutLocationAttempts>=maxRunningAttempts){returncurrentState;// Stop polling after 3 attempts}}elseif(currentState.hasLocationInfo()){runningWithoutLocationAttempts=0;// Reset when we hit a breakpoint}

This handles both scenarios:

  1. Paused → Continue → Running (normal case, returns after a few attempts)
  2. Running → Continue → Still Running (second continue, now returns after 3 attempts instead of hanging forever)

Testing Performed

Full debugging session test:

StepActionBefore FixAfter Fix
1Start debug session with attach config
2Set breakpoint on health endpoint
3Call health endpoint (background)
4Debugger pauses at breakpoint
5get_variables_values
6First continue_execution✅ Returns promptly✅ Returns promptly
7Second continue_executionHANGS FOREVER✅ Returns promptly
8Third continue_executionN/A (stuck)✅ Returns promptly
9stop_debuggingN/A✅ Session ends cleanly

Backward Compatibility

Fully backward compatible. The fix only affects the edge case where:

  • The debugger is already running (not paused)
  • continue_execution is called again

Normal debugging workflows (step, continue from breakpoint, etc.) are unaffected.

… times
When calling continue_execution while the debugger is already running (not
paused at a breakpoint), the waitForStateChange method would poll indefinitely
waiting for a state change that would never come.
Root cause:
- The early exit condition (beforeState.hasLocationInfo() && !currentState.hasLocationInfo())
only handled the case where we HAD location info before continuing
- When calling continue a second time, beforeState already had NO location info,
so the condition never matched and polling continued forever
Fix:
- Added tracking of consecutive attempts where process is running without location info
- After 3 such attempts, return the current state instead of polling forever
- Reset the counter when we get location info back (e.g., hitting a breakpoint)
This handles both scenarios:
1. Paused → Continue → Running (normal case, returns quickly)
2. Running → Continue → Still Running (second continue, now returns after 3 attempts)
Testing performed:
1. Start debug session with attach configuration
2. Set breakpoint on health endpoint
3. Call health endpoint in background
4. Debugger pauses at breakpoint - get_variables_values works
5. First continue_execution - returns promptly
6. Second continue_execution - previously hung forever, NOW returns promptly
7. Third continue_execution - returns with 'no location info' (expected)
8. Stop debugging - session ends cleanly
Sign up for freeto 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.

1 participant

@pitylend