open-consul/agent/cache
R.B. Boyer 9f41cc4a25
cache: prevent goroutine leak in agent cache (#14908)
There is a bug in the error handling code for the Agent cache subsystem discovered:

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.
2022-10-17 14:38:10 -05:00
..
cache.go cache: prevent goroutine leak in agent cache (#14908) 2022-10-17 14:38:10 -05:00
cache_test.go cache: prevent goroutine leak in agent cache (#14908) 2022-10-17 14:38:10 -05:00
entry.go lib/ttlcache: extract package from agent/cache 2020-10-20 19:10:20 -04:00
mock_Request.go test: update mockery use to put mocks into test files (#13656) 2022-07-05 16:57:15 -05:00
mock_Type.go test: update mockery use to put mocks into test files (#13656) 2022-07-05 16:57:15 -05:00
request.go test: update mockery use to put mocks into test files (#13656) 2022-07-05 16:57:15 -05:00
testing.go test: update mockery use to put mocks into test files (#13656) 2022-07-05 16:57:15 -05:00
type.go test: update mockery use to put mocks into test files (#13656) 2022-07-05 16:57:15 -05:00
watch.go proxycfg: remove dependency on `cache.UpdateEvent` (#13144) 2022-05-20 15:47:40 +01:00
watch_test.go bulk rewrite using this script 2022-01-20 10:46:23 -06:00