You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Controllers do not requeue events on transient errors #824
All of the controllers currently have a serious flaw, in that none of them retry / requeue events when a failure occurs processing the event. This means that certain operations will not complete until the controller is restarted.
Stories need to be created for beta2 for deployments and builds individually that correctly handle errors (probably by simply requeueing the event that triggered the error). This should be done in a way that does not overly complicate the controller loops (moves the logic for retry up a level). See the scheduler for ideas about how these events can be requeued. It's important to note that some controller loops will depend on order, so requeuing may result in operations delivered out of order, which means controller loops need to check that their action is valid (ie, if they already processed a newer event). It's also important that the controllers can make progress in the face of transient errors.
It would be good for one person to look at the problem as a whole and help ensure the logic is right. More unit and integration tests will need to be added to the controller, and a wider range of failure conditions detected. Better logging behavior should also be applied, so that it's easy to diagnose failures.
Given the nature of the current behavior, we may need to delay features from beta2 in favor of ensuing the controller loops are sound.
I think both build+deployment scenarios where it's due to a new image will need some careful logic.
I assume that if we're currently retrying an operation that was triggered by newImage:v2 and we get a new event for newimage:v3, we should abandon the retry logic that's operating on newImage:v2. If we don't, we end up with a race condition where the final outcome may be based on either newImage:v2 or newImage:v3.
But i'm not sure it's always going to be that clear which is the "newer" one. Nor am I sure we can really eliminate that race condition fully (ie once a build for newImage:v2 is running, it's basically out of our hands unless we cancel it)
In sum, I think there's a pretty deep rathole here of "what should the behavior be" that we need to discuss.
Deployments aren't a problem because there is a resource version attached to the IR - if you process it at time T0, fail, put it in the queue, and then process a different T1, you can use resource version to ignore the earlier T0. Builds and images should be possible as well - it's possible that writing the last image used to the trigger is wrong, and we should be writing the last IR version we see.
I think both build+deployment scenarios where it's due to a new image will need some careful logic.
I assume that if we're currently retrying an operation that was triggered by newImage:v2 and we get a new event for newimage:v3, we should abandon the retry logic that's operating on newImage:v2. If we don't, we end up with a race condition where the final outcome may be based on either newImage:v2 or newImage:v3.
But i'm not sure it's always going to be that clear which is the "newer" one. Nor am I sure we can really eliminate that race condition fully (ie once a build for newImage:v2 is running, it's basically out of our hands unless we cancel it)
In sum, I think there's a pretty deep rathole here of "what should the behavior be" that we need to discuss.
—
Reply to this email directly or view it on GitHub.
Agreed, this needs careful thought and brainstorming. We have to make sure the system converges forward where it can, and with things like builds and webhooks we do a best effort.
I think both build+deployment scenarios where it's due to a new image will need some careful logic.
I assume that if we're currently retrying an operation that was triggered by newImage:v2 and we get a new event for newimage:v3, we should abandon the retry logic that's operating on newImage:v2. If we don't, we end up with a race condition where the final outcome may be based on either newImage:v2 or newImage:v3.
But i'm not sure it's always going to be that clear which is the "newer" one. Nor am I sure we can really eliminate that race condition fully (ie once a build for newImage:v2 is running, it's basically out of our hands unless we cancel it)
In sum, I think there's a pretty deep rathole here of "what should the behavior be" that we need to discuss.
—
Reply to this email directly or view it on GitHub.
So i've done a study of the various build flows and come to the following conclusions:
First of all, this is all about creating a build/build pod. it has nothing to do with the ultimate successful completion of that build. (in case that's not obvious to anyone reading this).
With that in mind:
for webhook triggered builds (which are not queue-polling based anyway) we should not change things. We currently return appropriate http status codes on the webhook call, and if we're going to move to a model where we retry failures, the status codes we return would be come useless (either we'd have to always return 200 and hope that eventually we could succeed, or we'd have to perform a synchronous call to ensure the build was started (or conclude we couldn't start it) before returning. I suggest instead we keep things as is and put the onus on the webhook client to retry if so desired. I'm not sure what github actually does on a failed invocation, i'm guessing it won't retry, but again i'm not sure we can consistently do something smarter, so i prefer to that we simply report our failure reliably.
For the image change triggers poll loop, we could fail in two places:
a) could not create the build object definition due to issues looking up associated imagerepo data
b) failure posting the build object to the rest endpoint
long term we probably want to break this down into retryable errors (5xx) vs permanent failures (4xx)
For now, in both cases we should simply requeue and retry the image repo event in the same way the scheduler is doing it (this has the deficiency as noted by @ironcladlou that we have to re-pull the latest version of the object and if that fails we're stuck). The image repo event will always contain the most up to date tag data (since we re-pull it), so the worst case outcome here is that we got an image change repo event where the tag corresponded to v1, we failed, pulled the latest repo object, tag now points to v2, and we queued that. We'll ultimately run a build using image v2 and never have performed a build using image v1.
Since the "normal" flow would have resulted in 2 builds, one for v1 and then one for v2, we still end up in the same final state: the last build run is for v2 and any downstream deployments are done w/ that image.
risks:
a) race conditions on pulling the latest version of the object and enqueuing it. I don't think the scheduler addresses that today either.
b) permanent failures will retry forever
BuilderController polling loop. This is the bit responsible for seeing new Build objects and creating BuildPods. It also monitors BuildPod changes and updates Build status accordingly.
Failures in this flow are basically all due to api faliures (could not update status, could not create pod, etc). We should simply requeue the event (with a backoff and update) and try again, similar to scheduler behavior.
Longer term i'd like to address the indefinite failures with two additional strategies:
dividing api failures into retryable and non-retryable failures (don't requeue non-retryable failures)
compose a "retry count" field onto objects in the FIFO queues so the controllers can recognize when they've retried a particular event N times and stop retrying it.
So i've done a study of the various build flows and come to the following
conclusions:
First of all, this is all about creating a build/build pod. it has nothing
to do with the ultimate successful completion of that build. (in case
that's not obvious to anyone reading this).
With that in mind:
for webhook triggered builds (which are not queue-polling based anyway) we
should not change things. We currently return appropriate http status codes
on the webhook call, and if we're going to move to a model where we retry
failures, the status codes we return would be come useless (either we'd have
to always return 200 and hope that eventually we could succeed, or we'd have
to perform a synchronous call to ensure the build was started (or conclude
we couldn't start it) before returning. I suggest instead we keep things as
is and put the onus on the webhook client to retry if so desired. I'm not
sure what github actually does on a failed invocation, i'm guessing it won't
retry, but again i'm not sure we can consistently do something smarter, so i
prefer to that we simply report our failure reliably.
Agree - if you don't see 200 from your web hook, you retry, or you're not guaranteed to get a build.
For the image change triggers poll loop, we could fail in two places:
a) could not create the build object definition due to issues looking up
associated imagerepo data
b) failure posting the build object to the rest endpoint
long term we probably want to break this down into retryable errors
(5xx) vs permanent failures (4xx)
For now, in both cases we should simply requeue and retry the image repo
event in the same way the scheduler is doing it (this has the deficiency as
noted by @ironcladlou that we have to re-pull the latest version of the
object and if that fails we're stuck).
A future bit of work could be "identify items that are always failing and take punitive action", which is sending an event plus maybe blacklisting that item until the next resync.
The image repo event will always
contain the most up to date tag data (since we re-pull it), so the worst
case outcome here is that we got an image change repo event where the tag
corresponded to v1, we failed, pulled the latest repo object, tag now points
to v2, and we queued that. We'll ultimately run a build using image v2 and
never have performed a build using image v1.
Since the "normal" flow would have resulted in 2 builds, one for v1 and then
one for v2, we still end up in the same final state: the last build run is
for v2 and any downstream deployments are done w/ that image.
risks:
a) race conditions on pulling the latest version of the object and
enqueuing it. I don't think the scheduler addresses that today either.
b) permanent failures will retry forever
BuilderController polling loop. This is the bit responsible for seeing
new Build objects and creating BuildPods. It also monitors BuildPod changes
and updates Build status accordingly.
Failures in this flow are basically all due to api faliures (could not
update status, could not create pod, etc). We should simply requeue the
event (with a backoff and update) and try again, similar to scheduler
behavior.
Longer term i'd like to address the indefinite failures with two additional
strategies:
dividing api failures into retryable and non-retryable failures (don't
requeue non-retryable failures)
compose a "retry count" field onto objects in the FIFO queues so the
controllers can recognize when they've retried a particular event N times
and stop retrying it.
thoughts?
Like. I think of the controller loop communicating a certain error type back to the thing calling it (the helper code that does retries and queues and loops) like ErrPermFail. The helper code would be parameterizable on how to handle perm fail (probably just send an event).
risks: a) race conditions on pulling the latest version of the object and enqueuing it. I don't think the scheduler addresses that today either.
This is the issue I described in 4330. @smarterclayton, this is the main flaw I was trying to convey with using FIFO for retries. You can replace newer state with stale data in the queue. In the issue, I suggested one possible fix.
dividing api failures into retryable and non-retryable failures (don't
requeue non-retryable failures)
Typed errors to drive pluggable retry mechanics makes sense to me.
risks: a) race conditions on pulling the latest version of the object and enqueuing it. I don't think the scheduler addresses that today either.
This is the issue I described in 4330. @smarterclayton, this is the main flaw I was trying to convey with using FIFO for retries. You can replace newer state with stale data in the queue. In the issue, I suggested one possible fix.
Yes - you at minimum need to ensure you don't deliver new and then old, which is the implicit guarantee of fifo. Solvable as you noted by removing retry items from the retry queue when a newer item is about to be sent to nextstep()
dividing api failures into retryable and non-retryable failures (don't
requeue non-retryable failures)
Typed errors to drive pluggable retry mechanics makes sense to me.
—
Reply to this email directly or view it on GitHub.
Yes - you at minimum need to ensure you don't deliver new and then old, which is the implicit guarantee of fifo. Solvable as you noted by removing retry items from the retry queue when a newer item is about to be sent to nextstep()
I hadn't even thought of maintaining a retry queue... What I had suggested as a possibility elsewhere was to support versioning inside FIFO so that FIFO would no-op attempts to push new items which are deemed stale according to a pluggable versioning function. Then you can just re-fetch and push into the queue on retry, and if you raced (and lost) with the reflector adding some updated state to the queue while you were fetching, your old state would just silently get dropped internally.
Yes - you at minimum need to ensure you don't deliver new and then old, which is the implicit guarantee of fifo. Solvable as you noted by removing retry items from the retry queue when a newer item is about to be sent to nextstep()
I hadn't even thought of maintaining a retry queue... What I had suggested as a possibility elsewhere was to support versioning inside FIFO so that FIFO would no-op attempts to push new items which are deemed stale according to a pluggable versioning function (for instance). Then you can just re-fetch and push into the queue on retry, and if you raced (and lost) with the reflector adding some updated state to the queue while you were fetching, your old state would just silently get dropped internally.
You are getting events from the source of truth, you don't need to refetch anything. If you don't get an event, it didn't change.
—
Reply to this email directly or view it on GitHub.
@ironcladlou I was thinking of a similar path (creating an AddIfNotPresent method on FIFO) but the problem there is that if the newer item on the queue was consumed before the retry logic tried to push the old one onto the queue, you'd end up processing the old state after the new state. The only way to avoid that (that i've thought of) is for there to be only a single reader on the queue, and for the thread doing the reading to also be the thread doing the retry push. The problem with that is it means you can't really do a backoff before pushing the event (since you'd hang the controller loop), which means you end up potentially fast spinning in a fail/retry state.
@smarterclayton i don't follow your last comment. I think the issue @ironcladlou and I are discussing is the following scenario:
event A.1 is pushed onto the FIFO queue
controller pops it, attempts to process it, fails
event A.2 is pushed onto the FIFO queue
controller re-queues A.1 for retry
FIFO queue now contains only A.1 (due to the nature of the FIFO queue queuing items by key and resolving collisions by replacing with the last push).
controller loop pops A.1, attempts to process it again, will never process A.2 (barring a restart of the controller in which it refetches everything)
One way to address that is to refresh A prior to requeuing it, so instead of re-queuing A.1, the controller would end up "re"queuing A.2. But runs into the issues we've discussed:
race condition on the refresh/requeue
a failure to refresh results in a failure to requeue for retry
@ironcladlou I was thinking of a similar path (creating an AddIfNotPresent method on FIFO) but the problem there is that if the newer item on the queue was consumed before the retry logic tried to push the old one onto the queue, you'd end up processing the old state after the new state. The only way to avoid that (that i've thought of) is for there to be only a single reader on the queue, and for the thread doing the reading to also be the thread doing the retry push. The problem with that is it means you can't really do a backoff before pushing the event (since you'd hang the controller loop), which means you end up potentially fast spinning in a fail/retry state.
@smarterclayton i don't follow your last comment. I think the issue @ironcladlou and I are discussing is the following scenario:
event A.1 is pushed onto the FIFO queue
controller pops it, attempts to process it, fails
event A.2 is pushed onto the FIFO queue
controller re-queues A.1 for retry
FIFO queue now contains only A.1 (due to the nature of the FIFO queue queuing items by key and resolving collisions by replacing with the last push).
If you're going to requeue, you fix fifo not to do that. You resolve collisions via the resource version. FIFO is poorly named, but the use pattern is "give me the latest version of X to react to". A failure comes back onto the queue only if a newer item is not yet present.
controller loop pops A.1, attempts to process it again, will never process A.2 (barring a restart of the controller in which it refetches everything)
One way to address that is to refresh A prior to requeuing it, so instead of re-queuing A.1, the controller would end up "re"queuing A.2. But runs into the issues we've discussed:
race condition on the refresh/requeue
a failure to refresh results in a failure to requeue for retry
—
Reply to this email directly or view it on GitHub.
that hits the first part of my comment, which is that it's only safe to
assume FIFO will resolve collisions if you can guarantee the thing it would
collide with is still on the queue...
This is resolved by handling versioning inside the FIFO where the internal
map can be locked. Additionally, If we had this capability, we don't need a
separate retry queue.
The question right now is: how do we proceed? For now, I'm thinking we just
re-queue on retry like the scheduler does, with a TODO acknowledging that
there are races with the Reflector which can result event loss, fixable by
making the (or a) FIFO version-aware.
Retry without version-awareness removes our at-most-once guarantee.
Reply to this email directly or view it on GitHub: #824 (comment)
We're not the scheduler, we have ordering guarantees that have to be preserved. Reordering stale before unstale in deployment would result in racy behavior.
----- Original Message -----
Retry without version-awareness removes our at-most-once guarantee.
But do you agree we can live with it for now (as does the scheduler) and
address the problem next?
Reply to this email directly or view it on GitHub: #824 (comment)
We're not the scheduler, we have ordering guarantees that have to be preserved. Reordering stale before unstale in deployment would result in racy behavior.
Do you agree that version handling in FIFO is the best way to address the problem for our needs? If so, should I be working on an upstream change, or do we need to introduce our own variant downstream for the time being? If not, what's the alternative design?
We're not the scheduler, we have ordering guarantees that have to be
preserved. Reordering stale before unstale in deployment would result in
racy behavior.
Do you agree that version handling in FIFO is the best way to address the
problem for our needs? If so, should I be working on an upstream change, or
do we need to introduce our own variant downstream for the time being? If
not, what's the alternative design?
Reply to this email directly or view it on GitHub: #824 (comment)
I think we should go ahead and close this issue as resolved, and spawn new issues for any problems that arise with the recently added retry implementations.
Activity
smarterclayton commentedon Feb 1, 2015
https://github.com/GoogleCloudPlatform/kubernetes/blob/master/plugin/pkg/scheduler/factory/factory.go#L225 Is an example from the scheduler, where pods can be unordered. Deployments need to ignore duplicates (but are set up to do so). Builds will need a bit more work in the case of image changes
bparees commentedon Feb 1, 2015
I think both build+deployment scenarios where it's due to a new image will need some careful logic.
I assume that if we're currently retrying an operation that was triggered by newImage:v2 and we get a new event for newimage:v3, we should abandon the retry logic that's operating on newImage:v2. If we don't, we end up with a race condition where the final outcome may be based on either newImage:v2 or newImage:v3.
But i'm not sure it's always going to be that clear which is the "newer" one. Nor am I sure we can really eliminate that race condition fully (ie once a build for newImage:v2 is running, it's basically out of our hands unless we cancel it)
In sum, I think there's a pretty deep rathole here of "what should the behavior be" that we need to discuss.
smarterclayton commentedon Feb 1, 2015
Deployments aren't a problem because there is a resource version attached to the IR - if you process it at time T0, fail, put it in the queue, and then process a different T1, you can use resource version to ignore the earlier T0. Builds and images should be possible as well - it's possible that writing the last image used to the trigger is wrong, and we should be writing the last IR version we see.
smarterclayton commentedon Feb 1, 2015
Agreed, this needs careful thought and brainstorming. We have to make sure the system converges forward where it can, and with things like builds and webhooks we do a best effort.
bparees commentedon Feb 2, 2015
trello card for build side of things: https://trello.com/c/8tI8Hzh2/491-handle-error-conditions-in-build-controllers
ironcladlou commentedon Feb 2, 2015
Trello card for deployments: https://trello.com/c/qDeHffOz
bparees commentedon Feb 13, 2015
So i've done a study of the various build flows and come to the following conclusions:
First of all, this is all about creating a build/build pod. it has nothing to do with the ultimate successful completion of that build. (in case that's not obvious to anyone reading this).
With that in mind:
for webhook triggered builds (which are not queue-polling based anyway) we should not change things. We currently return appropriate http status codes on the webhook call, and if we're going to move to a model where we retry failures, the status codes we return would be come useless (either we'd have to always return 200 and hope that eventually we could succeed, or we'd have to perform a synchronous call to ensure the build was started (or conclude we couldn't start it) before returning. I suggest instead we keep things as is and put the onus on the webhook client to retry if so desired. I'm not sure what github actually does on a failed invocation, i'm guessing it won't retry, but again i'm not sure we can consistently do something smarter, so i prefer to that we simply report our failure reliably.
For the image change triggers poll loop, we could fail in two places:
a) could not create the build object definition due to issues looking up associated imagerepo data
b) failure posting the build object to the rest endpoint
For now, in both cases we should simply requeue and retry the image repo event in the same way the scheduler is doing it (this has the deficiency as noted by @ironcladlou that we have to re-pull the latest version of the object and if that fails we're stuck). The image repo event will always contain the most up to date tag data (since we re-pull it), so the worst case outcome here is that we got an image change repo event where the tag corresponded to v1, we failed, pulled the latest repo object, tag now points to v2, and we queued that. We'll ultimately run a build using image v2 and never have performed a build using image v1.
Since the "normal" flow would have resulted in 2 builds, one for v1 and then one for v2, we still end up in the same final state: the last build run is for v2 and any downstream deployments are done w/ that image.
risks:
a) race conditions on pulling the latest version of the object and enqueuing it. I don't think the scheduler addresses that today either.
b) permanent failures will retry forever
Failures in this flow are basically all due to api faliures (could not update status, could not create pod, etc). We should simply requeue the event (with a backoff and update) and try again, similar to scheduler behavior.
Longer term i'd like to address the indefinite failures with two additional strategies:
thoughts?
smarterclayton commentedon Feb 13, 2015
----- Original Message -----
Agree - if you don't see 200 from your web hook, you retry, or you're not guaranteed to get a build.
A future bit of work could be "identify items that are always failing and take punitive action", which is sending an event plus maybe blacklisting that item until the next resync.
Like. I think of the controller loop communicating a certain error type back to the thing calling it (the helper code that does retries and queues and loops) like ErrPermFail. The helper code would be parameterizable on how to handle perm fail (probably just send an event).
ironcladlou commentedon Feb 13, 2015
This is the issue I described in 4330. @smarterclayton, this is the main flaw I was trying to convey with using FIFO for retries. You can replace newer state with stale data in the queue. In the issue, I suggested one possible fix.
Typed errors to drive pluggable retry mechanics makes sense to me.
smarterclayton commentedon Feb 13, 2015
ironcladlou commentedon Feb 14, 2015
I hadn't even thought of maintaining a retry queue... What I had suggested as a possibility elsewhere was to support versioning inside FIFO so that FIFO would no-op attempts to push new items which are deemed stale according to a pluggable versioning function. Then you can just re-fetch and push into the queue on retry, and if you raced (and lost) with the reflector adding some updated state to the queue while you were fetching, your old state would just silently get dropped internally.
smarterclayton commentedon Feb 14, 2015
bparees commentedon Feb 16, 2015
@ironcladlou I was thinking of a similar path (creating an AddIfNotPresent method on FIFO) but the problem there is that if the newer item on the queue was consumed before the retry logic tried to push the old one onto the queue, you'd end up processing the old state after the new state. The only way to avoid that (that i've thought of) is for there to be only a single reader on the queue, and for the thread doing the reading to also be the thread doing the retry push. The problem with that is it means you can't really do a backoff before pushing the event (since you'd hang the controller loop), which means you end up potentially fast spinning in a fail/retry state.
@smarterclayton i don't follow your last comment. I think the issue @ironcladlou and I are discussing is the following scenario:
event A.1 is pushed onto the FIFO queue
controller pops it, attempts to process it, fails
event A.2 is pushed onto the FIFO queue
controller re-queues A.1 for retry
FIFO queue now contains only A.1 (due to the nature of the FIFO queue queuing items by key and resolving collisions by replacing with the last push).
controller loop pops A.1, attempts to process it again, will never process A.2 (barring a restart of the controller in which it refetches everything)
One way to address that is to refresh A prior to requeuing it, so instead of re-queuing A.1, the controller would end up "re"queuing A.2. But runs into the issues we've discussed:
smarterclayton commentedon Feb 16, 2015
9 remaining items
smarterclayton commentedon Feb 16, 2015
----- Original Message -----
Retry without version-awareness removes our at-most-once guarantee.
ironcladlou commentedon Feb 16, 2015
But do you agree we can live with it for now (as does the scheduler) and address the problem next?
smarterclayton commentedon Feb 16, 2015
We're not the scheduler, we have ordering guarantees that have to be preserved. Reordering stale before unstale in deployment would result in racy behavior.
----- Original Message -----
ironcladlou commentedon Feb 16, 2015
@smarterclayton
Do you agree that version handling in FIFO is the best way to address the problem for our needs? If so, should I be working on an upstream change, or do we need to introduce our own variant downstream for the time being? If not, what's the alternative design?
smarterclayton commentedon Feb 16, 2015
I don't care whether it's upstream right now, just as long as it has a path to go upstream.
----- Original Message -----
Refactor deploy controllers to use RetryController
ironcladlou commentedon Mar 2, 2015
I think we should go ahead and close this issue as resolved, and spawn new issues for any problems that arise with the recently added retry implementations.
bparees commentedon Mar 2, 2015
the build controller update hasn't merged yet: #1194
ironcladlou commentedon Mar 2, 2015
Oops, sorry! Jumped the gun
ironcladlou commentedon Mar 20, 2015
This should be closed.