Skip to content

Backport of cache: prevent goroutine leak in agent cache into release/1.12.x#15017

Merged
hc-github-team-consul-core merged 1 commit into
release/1.12.xfrom
backport/fix-agent-cache-leak/sharply-sincere-salmon
Oct 17, 2022
Merged

Backport of cache: prevent goroutine leak in agent cache into release/1.12.x#15017
hc-github-team-consul-core merged 1 commit into
release/1.12.xfrom
backport/fix-agent-cache-leak/sharply-sincere-salmon

Conversation

@hc-github-team-consul-core
Copy link
Copy Markdown
Collaborator

Backport

This PR is auto-generated from #14908 to be assessed for backporting due to the inclusion of the label backport/1.12.

The below text is copied from the body of the original PR.


Description

There is a bug in the error handling code for the Agent cache subsystem discovered by @boxofrad :

  1. NotifyCallback calls notifyBlockingQuery which calls getWithIndex in a loop (which backs off on-error up to 1 minute)
  2. getWithIndex calls fetch if there’s no valid entry in the cache
  3. fetch starts a goroutine which calls Fetch on the cache-type, waits for a while (again with backoff up to 1 minute for errors) and then calls fetch to trigger a refresh

The end result being that every 1 minute notifyBlockingQuery spawns an ancestry of goroutines that essentially lives forever.

This PR ensures that the goroutine started by fetch cancels any prior goroutine spawned by the same line for the same key.

In isolated testing where a cache type was tweaked to indefinitely error, this patch prevented goroutine counts from skyrocketing.


Overview of commits

@hc-github-team-consul-core hc-github-team-consul-core force-pushed the backport/fix-agent-cache-leak/sharply-sincere-salmon branch from 5d2cc5b to be95638 Compare October 17, 2022 19:38
@hc-github-team-consul-core hc-github-team-consul-core merged commit 06d0935 into release/1.12.x Oct 17, 2022
@hc-github-team-consul-core hc-github-team-consul-core deleted the backport/fix-agent-cache-leak/sharply-sincere-salmon branch October 17, 2022 19:38
@github-actions github-actions Bot added the theme/agent-cache Agent Cache label Oct 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants