open-consul/agent/cache
R.B. Boyer a01936442c
cache: refactor agent cache fetching to prevent unnecessary fetches on error (#14956)
This continues the work done in #14908 where a crude solution to prevent a
goroutine leak was implemented. The former code would launch a perpetual
goroutine family every iteration (+1 +1) and the fixed code simply caused a
new goroutine family to first cancel the prior one to prevent the
leak (-1 +1 == 0).

This PR refactors this code completely to:

- make it more understandable
- remove the recursion-via-goroutine strangeness
- prevent unnecessary RPC fetches when the prior one has errored.

The core issue arose from a conflation of the entry.Fetching field to mean:

- there is an RPC (blocking query) in flight right now
- there is a goroutine running to manage the RPC fetch retry loop

The problem is that the goroutine-leak-avoidance check would treat
Fetching like (2), but within the body of a goroutine it would flip that
boolean back to false before the retry sleep. This would cause a new
chain of goroutines to launch which #14908 would correct crudely.

The refactored code uses a plain for-loop and changes the semantics
to track state for "is there a goroutine associated with this cache entry"
instead of the former.

We use a uint64 unique identity per goroutine instead of a boolean so
that any orphaned goroutines can tell when they've been replaced when
the expiry loop deletes a cache entry while the goroutine is still running
and is later replaced.
2022-10-25 10:27:26 -05:00
..
cache.go cache: refactor agent cache fetching to prevent unnecessary fetches on error (#14956) 2022-10-25 10:27:26 -05:00
cache_test.go cache: refactor agent cache fetching to prevent unnecessary fetches on error (#14956) 2022-10-25 10:27:26 -05:00
entry.go cache: refactor agent cache fetching to prevent unnecessary fetches on error (#14956) 2022-10-25 10:27:26 -05: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 Regenerate files according to 1.19.2 formatter 2022-10-24 16:12:08 -04:00
testing.go test: update mockery use to put mocks into test files (#13656) 2022-07-05 16:57:15 -05:00
type.go Regenerate files according to 1.19.2 formatter 2022-10-24 16:12:08 -04:00
watch.go cache: refactor agent cache fetching to prevent unnecessary fetches on error (#14956) 2022-10-25 10:27:26 -05:00
watch_test.go bulk rewrite using this script 2022-01-20 10:46:23 -06:00