open-nomad/helper
Michael Schurter 3b57df33e3
client: fix data races in config handling (#14139)
Before this change, Client had 2 copies of the config object: config and configCopy. There was no guidance around which to use where (other than configCopy's comment to pass it to alloc runners), both are shared among goroutines and mutated in data racy ways. At least at one point I think the idea was to have `config` be mutable and then grab a lock to overwrite `configCopy`'s pointer atomically. This would have allowed alloc runners to read their config copies in data race safe ways, but this isn't how the current implementation worked.

This change takes the following approach to safely handling configs in the client:

1. `Client.config` is the only copy of the config and all access must go through the `Client.configLock` mutex
2. Since the mutex *only protects the config pointer itself and not fields inside the Config struct:* all config mutation must be done on a *copy* of the config, and then Client's config pointer is overwritten while the mutex is acquired. Alloc runners and other goroutines with the old config pointer will not see config updates.
3. Deep copying is implemented on the Config struct to satisfy the previous approach. The TLS Keyloader is an exception because it has its own internal locking to support mutating in place. An unfortunate complication but one I couldn't find a way to untangle in a timely fashion.
4. To facilitate deep copying I made an *internally backward incompatible API change:* our `helper/funcs` used to turn containers (slices and maps) with 0 elements into nils. This probably saves a few memory allocations but makes it very easy to cause panics. Since my new config handling approach uses more copying, it became very difficult to ensure all code that used containers on configs could handle nils properly. Since this code has caused panics in the past, I fixed it: nil containers are copied as nil, but 0-element containers properly return a new 0-element container. No more "downgrading to nil!"
2022-08-18 16:32:04 -07:00
..
args
boltdd client: add support for checks in nomad services 2022-07-12 17:09:50 -05:00
broker core: allow pausing and un-pausing of leader broker routine (#13045) 2022-07-06 16:13:48 +02:00
bufconndialer test: test the buffered pipe used by nsd (#12563) 2022-04-14 08:38:25 -07:00
codec Provide mock secure variables implementation (#12980) 2022-07-11 13:34:03 -04:00
constraints/semver
discover
envoy
escapingfs test: use T.TempDir to create temporary test directory (#12853) 2022-05-12 11:42:40 -04:00
escapingio build: run gofmt on all go source files 2022-08-16 11:14:11 -05:00
fields
flags
flatmap
freeport
gated-writer
grpc-middleware/logging
ipaddr
logging
mount
noxssrw
pluginutils cleanup: replace TypeToPtr helper methods with pointer.Of (#14151) 2022-08-17 18:26:34 +02:00
pointer client: fix data races in config handling (#14139) 2022-08-18 16:32:04 -07:00
pool rpc: fix race in conn last used tracking (#14173) 2022-08-17 14:57:53 -07:00
raftutil move secure variable conflict resolution to state store (#13922) 2022-08-15 11:19:53 -04:00
snapshot snapshot restore-from-archive streaming and filtering (#13658) 2022-07-11 10:48:00 -04:00
stats
testlog tests: add a space between node name and timestamp (#13750) 2022-07-13 16:23:03 -04:00
testtask
tlsutil
useragent
uuid
winsvc
cluster.go feat: remove dependency to consul/lib 2022-04-09 13:22:44 +02:00
eof.go feat: remove dependency to consul/lib 2022-04-09 13:22:44 +02:00
funcs.go client: fix data races in config handling (#14139) 2022-08-18 16:32:04 -07:00
funcs_test.go client: fix data races in config handling (#14139) 2022-08-18 16:32:04 -07:00
math.go feat: remove dependency to consul/lib 2022-04-09 13:22:44 +02:00
path.go feat: remove dependency to consul/lib 2022-04-09 13:22:44 +02:00