Skip to content

Return watch AbortController immediately to enable cancellation before first event#2877

Draft
Copilot wants to merge 3 commits into
mainfrom
copilot/cancel-watches
Draft

Return watch AbortController immediately to enable cancellation before first event#2877
Copilot wants to merge 3 commits into
mainfrom
copilot/cancel-watches

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 26, 2026

Watch.watch() could block the returned Promise<AbortController> until the stream produced output, which made idle/dead-watch recovery hard when no events arrived (for example with resourceVersion-based watches). This change makes cancellation available immediately while preserving existing watch lifecycle/error semantics.

  • Behavior change: make controller availability immediate

    • watch.watch(...) now returns the AbortController immediately after setup, instead of waiting for auth/fetch/stream startup.
    • Watch startup work (applySecurityAuthentication + fetch + stream wiring) now runs asynchronously, and still funnels failures through done(...) via existing doneCallOnce logic.
  • Error/lifecycle handling preserved

    • Existing guarantees remain intact:
      • done is still single-invocation.
      • timeout and abort paths still map to the same error flow.
      • non-200 responses still surface through done with status-aware error construction.
  • Targeted test updates

    • Added coverage for “controller is returned before any response data is received,” then aborting that controller and asserting AbortError.
    • Updated one pre-existing test to account for async startup timing (wait for done instead of assuming synchronous completion).
const controller = await watch.watch(
  '/api/v1/pods',
  { resourceVersion: rv },
  onEvent,
  onDone,
);

// now available immediately, even before first event arrives
controller.abort();

@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 26, 2026
Copilot AI linked an issue May 26, 2026 that may be closed by this pull request
@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels May 26, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Copilot
Once this PR has been reviewed and has the lgtm label, please ask for approval from brendandburns. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels May 26, 2026
Copilot AI changed the title [WIP] Fix unresolved promise issue with watch.abort() Return watch AbortController immediately to enable cancellation before first event May 26, 2026
Copilot AI requested a review from brendandburns May 26, 2026 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cancel watches

3 participants