Skip to content

Backport of cache: prevent goroutine leak in agent cache into release/1.13.x#15018

Merged
hc-github-team-consul-core merged 1 commit intorelease/1.13.xfrom
backport/fix-agent-cache-leak/steadily-prime-falcon
Oct 17, 2022
Merged

Backport of cache: prevent goroutine leak in agent cache into release/1.13.x#15018
hc-github-team-consul-core merged 1 commit intorelease/1.13.xfrom
backport/fix-agent-cache-leak/steadily-prime-falcon

Conversation

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

Backport

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

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 merged commit b2f8c89 into release/1.13.x Oct 17, 2022
@hc-github-team-consul-core hc-github-team-consul-core force-pushed the backport/fix-agent-cache-leak/steadily-prime-falcon branch from 3fb3c5e to b6fb21f Compare October 17, 2022 19:38
@hc-github-team-consul-core hc-github-team-consul-core deleted the backport/fix-agent-cache-leak/steadily-prime-falcon 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