Skip to content

fix(testing): resolve result pipe drain promptly on cancellation - #26231

Open
MOHAMMED WASIM KHAN (wasim-builds) wants to merge 1 commit into
microsoft:mainfrom
wasim-builds:fix-26217-macos-pytest-drain-timeout
Open

MOHAMMED WASIM KHAN (wasim-builds) wants to merge 1 commit into
microsoft:mainfrom
wasim-builds:fix-26217-macos-pytest-drain-timeout

Conversation

@wasim-builds

Copy link
Copy Markdown

Fixes #26217

Description

On non-Windows platforms (especially macOS), non-blocking FIFO sockets do not emit an end or close event when the Python subprocess writer exits. Because startRunResultNamedPipe previously relied solely on reader.onClose to resolve deferredTillServerClose, pytest runs always hung until awaitDeferredWithTimeout hit the 5,000ms RESULT_PIPE_DRAIN_TIMEOUT_MS fallback, adding an unnecessary 5-second delay to every test run.

Changes

  • In src/client/testing/testController/common/utils.ts:
    • Added RESULT_PIPE_DRAIN_GRACE_PERIOD_MS = 100.
    • When cancellationToken is cancelled (triggered either by user cancellation or when the subprocess finishes and invokes serverCancel.cancel()), start a 100ms drain grace timer to allow buffered messages to be received before disposing the pipe and resolving deferredTillServerClose.
    • If reader.onClose fires before the grace period (e.g. on Windows/Linux), the drain timer is cleared and the pipe is disposed immediately.
  • Added regression test in src/test/testing/testController/utils.unit.test.ts verifying prompt resolution under cancellation when the reader does not emit close events.

Fixes microsoft#26217

On non-Windows platforms (especially macOS), non-blocking FIFO sockets
do not emit an end or close event when the python subprocess writer exits.
Because the server close deferred previously relied exclusively on reader.onClose
after PR microsoft#25981, test runs always waited for the full RESULT_PIPE_DRAIN_TIMEOUT_MS
(5 seconds) to expire.

This change starts a short drain grace timer (100ms) upon cancellation or
subprocess completion (via cancellationToken.onCancellationRequested) so
buffered messages can finish draining while ensuring the result pipe resolves
promptly without hanging on systems where reader.onClose does not fire.
Copilot AI balanced review requested due to automatic review settings October 17, 2026 10:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

pytest runs always take an extra ~5 s on macOS since 2026.8.0 (result pipe close never detected, drain timeout always hit)

2 participants