-
Notifications
You must be signed in to change notification settings - Fork 40.9k
Handle context in the process loop #132005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Handle context in the process loop #132005
Conversation
Hi @kei01234kei. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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. |
case <-ctx.Done(): | ||
return | ||
default: | ||
_, err := c.config.Queue.Pop(PopProcessFunc(c.config.Process)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this block indefinitely?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Pop
method can block indefinitely for some reason, but it is clear that this is not intentional, considering that the method acquires a lock for its entire execution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If Pop can block indefinitely, then adding context here won't actually be respected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would also need to accept context, or have some timeout or ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If Pop can block indefinitely, then adding context here won't actually be respected?
I read the code carefully again, and I realized that Pop does not block indefinitely.
Pop is blocked when Wait
is called here.
kubernetes/staging/src/k8s.io/client-go/tools/cache/delta_fifo.go
Lines 497 to 506 in 00d3750
for len(f.queue) == 0 { | |
// When the queue is empty, invocation of Pop() is blocked until new item is enqueued. | |
// When Close() is called, the f.closed is set and the condition is broadcasted. | |
// Which causes this loop to continue and return from the Pop(). | |
if f.closed { | |
return nil, ErrFIFOClosed | |
} | |
f.cond.Wait() | |
} |
However, when the ctx is done, Close
is called, which then calls Broadcast
here.
kubernetes/staging/src/k8s.io/client-go/tools/cache/controller.go
Lines 150 to 153 in 00d3750
go func() { | |
<-ctx.Done() | |
c.config.Queue.Close() | |
}() |
This means Pop can return.
That's why Pop does not block indefinitely.
/triage accpeted |
@BenTheElder: The label(s) In response to this:
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. |
(@BenTheElder, Triage is not accepted yet.) |
ah, fwiw this just removes it from the triage queue, it doesn't impact merging etc |
/ok-to-test |
67faafa
to
2cd5dbb
Compare
@BenTheElder |
hi! Can you get ci through first? 😄 |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: kei01234kei The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
To address the TODO comment.
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: