Skip to content

fix(mock): stop ListAndWatch when the kubelet stream closes - #30

Open
blackdragoon26 wants to merge 1 commit into
Project-HAMi:masterfrom
blackdragoon26:fix/issue-29
Open

blackdragoon26 wants to merge 1 commit into
Project-HAMi:masterfrom
blackdragoon26:fix/issue-29

Conversation

@blackdragoon26

@blackdragoon26 blackdragoon26 commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

What type of PR is this?

/kind bug

What this PR does / why we need it:

ListAndWatch ignored send errors and kept rebuilding the device list every ten seconds after kubelet disconnected. The handler now returns the send error and exits promptly if kubelet cancels the stream between updates.

Which issue(s) this PR fixes:

Fixes #29

How this was tested:

Added regression tests for a failed send and cancellation after the first device update. go test -race ./... passed.

AI assistance was used for this PR, but personally reviewed by me.

Summary by CodeRabbit

  • Bug Fixes
    • Device list updates now stop promptly when the stream is canceled and report errors if an update cannot be sent, rather than continuing to wait before the next update.
  • Tests
    • Added coverage for send failures and stream cancellation.

Signed-off-by: blackdragoon26 <sankalp.jha9643@gmail.com>
@hami-robot

hami-robot Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

@blackdragoon26: The label(s) kind/bug cannot be applied, because the repository doesn't have them.

Details

In response to this:

What type of PR is this?

/kind bug

What this PR does / why we need it:

ListAndWatch ignored send errors and kept rebuilding the device list every ten seconds after kubelet disconnected. The handler now returns the send error and exits promptly if kubelet cancels the stream between updates.

Which issue(s) this PR fixes:

Fixes #29

How this was tested:

Added regression tests for a failed send and cancellation after the first device update. go test -race ./... passed.

AI assistance was used for this PR, but personally reviewed by me.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@hami-robot

hami-robot Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: blackdragoon26
Once this PR has been reviewed and has the lgtm label, please assign archlitchi for approval. For more information see the Kubernetes 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

@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

ListAndWatch now returns errors from failed sends and exits when the stream context is done. A test covers send errors and context cancellation.

Changes: Watch lifecycle

Layer / File(s) Summary
Watch loop and disconnect tests
internal/pkg/mock/server.go, internal/pkg/mock/server_test.go
ListAndWatch returns an error when Send fails and returns the context error when the stream context is done. Tests check both outcomes.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: archlitchi

Merge Risk: Minimal · up to 5aa31

This change makes the device plugin stop its watch loop when kubelet disconnects, rather than continuing to rebuild device lists in the background. Healthy streams keep receiving periodic updates. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: ListAndWatch in the mock plugin now stops when the kubelet stream closes. The raw summary confirms the handler returns the send error and exits on context cancellation…
Linked Issues check Passed Issue #29 requires three behaviors: (1) return on a Send error, (2) exit promptly when the stream is canceled between updates, and (3) keep sending periodic updates on healthy streams. At head, intern…
Out of Scope Changes check Passed The PR changes two files according to the summary: internal/pkg/mock/server.go (+8/-2) and internal/pkg/mock/server_test.go (+78/-0). The server.go change touches only the ListAndWatch send and wait l…
Full details: Title check

Explanation

The title names the main change: ListAndWatch in the mock plugin now stops when the kubelet stream closes. The raw summary confirms the handler returns the send error and exits on context cancellation instead of sleeping unconditionally. The title is specific and matches the linked issue #29 and the PR objectives. It uses the conventional fix(scope) prefix and is 59 characters long.

Full details: Linked Issues check

Explanation

Issue #29 requires three behaviors: (1) return on a Send error, (2) exit promptly when the stream is canceled between updates, and (3) keep sending periodic updates on healthy streams. At head, internal/pkg/mock/server.go MockPlugin.ListAndWatch checks s.Send(...) and returns the error (behavior 1). The loop then waits in a select on s.Context().Done() and time.After(10 * time.Second). On cancellation it returns s.Context().Err() (behavior 2). When no cancellation occurs, the loop repeats after 10 seconds (behavior 3). The summary also reports server_test.go coverage for a failed send and for cancellation after the first update. I did not read the test file contents directly, and the whole-PR diff was unavailable, so the base-to-head change was confirmed from the head file and the summary only. The head code alone establishes the required behavior.

Full details: Out of Scope Changes check

Explanation

The PR changes two files according to the summary: internal/pkg/mock/server.go (+8/-2) and internal/pkg/mock/server_test.go (+78/-0). The server.go change touches only the ListAndWatch send and wait logic that issue #29 describes. The test file adds a regression test for that same handler. No unrelated changes appear in the summary. The whole-PR diff could not be read, so this verdict relies on the summary's file list and line counts.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit watches lists go by
A send error ends the watch
A cancelled stream ends the wait
No extra update follows
The burrow rests in quiet

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ffd0ca74-992a-4684-a66a-295b7bc6ae54
Commits

Reviewing files that changed from the base of the PR and between 8be1424 and 5aa3142.

Files selected for processing: 2

  • internal/pkg/mock/server.go
  • internal/pkg/mock/server_test.go

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

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.

ListAndWatch keeps sending after the kubelet stream closes

1 participant