Skip to content

Stop scheduled status checks on watch cancellation - #46

Merged
stefanprodan merged 2 commits into
mainfrom
fix/status-check-cancel-select
Nov 26, 2026
Merged

stefanprodan merged 2 commits into
mainfrom
fix/status-check-cancel-select

Conversation

@stefanprodan

@stefanprodan stefanprodan commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #45.

  • newStatusCheckTaskFunc now drops the result if the informer context is done after the read, and selects on ctx.Done() while sending it. Since Fix send on closed channel panic from scheduled status checks #45 the informer waits for scheduled checks before closing eventCh, so an unconditional send could block shutdown on a consumer that stopped reading.
  • taskManager.Schedule checks parentCtx.Err() before running the task. When the task timer and the parent context are both done, select picks a case at random, so the check could run after the watch was cancelled.
  • eventFunnel.drain drops 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 left drain blocked, 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

  • New TestEventFunnelClosesWithoutConsumer: cancels the funnel without reading its output, then requires senders to proceed and the funnel to close. It fails without the drain change.
  • TestStopWaitsForScheduledStatusCheck now also requires that the scheduled check's result isn't sent after the watch is stopped.
  • make test (with -race) and make lint pass.

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>
@stefanprodan stefanprodan added the bug Something isn't working label Nov 26, 2026

@matheuscscp matheuscscp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@stefanprodan
stefanprodan merged commit 0cd2b81 into main Nov 26, 2026
3 checks passed
@stefanprodan
stefanprodan deleted the fix/status-check-cancel-select branch November 26, 2026 08:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants