Repository navigation
Stop scheduled status checks on watch cancellation - #46
Merged
Merged
Conversation
A scheduled status check sent its result on the event channel without checking the informer context. Since #45, the informer waits for these checks before closing the channel, so a consumer that stopped reading could block shutdown. Drop the result if the watch has stopped, and select on the context while sending. When both the task timer and the parent context are done, select picks a case at random, so the check could still run after cancellation. Check the parent context before running the task. Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
The event funnel forwarded each event to its output channel with a blocking send. A consumer that cancelled the watch and stopped reading left the drain goroutine blocked, and with it every informer handler, scheduled status check and error report waiting to send, so the informers never exited and the output channel was never closed. Once the funnel context is done, drop events the output channel can't take, while still reading each input channel until it is closed. Add a funnel test for a consumer that stops reading, and check that a scheduled status check result isn't sent after the watch is stopped. Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #45.
newStatusCheckTaskFuncnow drops the result if the informer context is done after the read, and selects onctx.Done()while sending it. Since Fix send on closed channel panic from scheduled status checks #45 the informer waits for scheduled checks before closingeventCh, so an unconditional send could block shutdown on a consumer that stopped reading.taskManager.SchedulechecksparentCtx.Err()before running the task. When the task timer and the parent context are both done,selectpicks a case at random, so the check could run after the watch was cancelled.eventFunnel.draindrops events the output channel can't take once the funnel context is done, and keeps reading each input channel until it is closed. Before, a consumer that cancelled the watch and stopped reading leftdrainblocked, and with it every handler, scheduled check and error report waiting to send, so informers never exited and the output channel never closed. Stopping a single informer (CRD or namespace deleted) is unaffected, as the funnel context is still live.Testing
TestEventFunnelClosesWithoutConsumer: cancels the funnel without reading its output, then requires senders to proceed and the funnel to close. It fails without thedrainchange.TestStopWaitsForScheduledStatusChecknow also requires that the scheduled check's result isn't sent after the watch is stopped.make test(with-race) andmake lintpass.