open-consul/agent/grpc-internal
Dan Upton 118ffb1e95
grpc: fix data race in balancer registration (#16229)
Registering gRPC balancers is thread-unsafe because they are stored in a
global map variable that is accessed without holding a lock. Therefore,
it's expected that balancers are registered _once_ at the beginning of
your program (e.g. in a package `init` function) and certainly not after
you've started dialing connections, etc.

> NOTE: this function must only be called during initialization time
> (i.e. in an init() function), and is not thread-safe.

While this is fine for us in production, it's challenging for tests that
spin up multiple agents in-memory. We currently register a balancer per-
agent which holds agent-specific state that cannot safely be shared.

This commit introduces our own registry that _is_ thread-safe, and
implements the Builder interface such that we can call gRPC's `Register`
method once, on start-up. It uses the same pattern as our resolver
registry where we use the dial target's host (aka "authority"), which is
unique per-agent, to determine which builder to use.
2023-02-28 10:18:38 +00:00
..
balancer grpc: fix data race in balancer registration (#16229) 2023-02-28 10:18:38 +00:00
resolver grpc: switch servers and retry on error (#15892) 2023-01-05 10:21:27 +00:00
services/subscribe Protobuf Refactoring for Multi-Module Cleanliness (#16302) 2023-02-17 16:14:46 -05:00
client.go grpc: fix data race in balancer registration (#16229) 2023-02-28 10:18:38 +00:00
client_test.go grpc: fix data race in balancer registration (#16229) 2023-02-28 10:18:38 +00:00
handler.go grpc: `protoc` plugin for generating gRPC rate limit specifications (#15564) 2023-01-04 16:07:02 +00:00
handler_test.go grpc: fix data race in balancer registration (#16229) 2023-02-28 10:18:38 +00:00
server_test.go Rate Limit Handler - ensure rate limiting is not in the code path when not configured (#15819) 2022-12-20 15:00:22 -07:00
stats_test.go Protobuf Refactoring for Multi-Module Cleanliness (#16302) 2023-02-17 16:14:46 -05:00
tracker.go grpc: switch servers and retry on error (#15892) 2023-01-05 10:21:27 +00:00