open-consul/agent/consul
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
..
auth
authmethod
autopilotevents
controller
discoverychain
fsm
gateways
multilimiter
prepared_query
rate
servercert
state
stream
testdata
usagemetrics
wanfed
watch
xdscapacity
acl.go
acl_authmethod.go
acl_authmethod_oss.go
acl_client.go
acl_endpoint.go
acl_endpoint_oss.go
acl_endpoint_test.go
acl_oss.go
acl_oss_test.go
acl_replication.go
acl_replication_test.go
acl_replication_types.go
acl_server.go
acl_server_oss.go
acl_test.go
acl_token_exp.go
acl_token_exp_test.go
auto_config_backend.go
auto_config_backend_test.go
auto_config_endpoint.go
auto_config_endpoint_test.go
auto_encrypt_endpoint.go
auto_encrypt_endpoint_test.go
autopilot.go
autopilot_oss.go
autopilot_test.go
catalog_endpoint.go
catalog_endpoint_test.go
client.go
client_serf.go
client_test.go
cluster_test.go
config.go
config_endpoint.go
config_endpoint_test.go
config_oss.go
config_replication.go
config_replication_test.go
config_test.go
connect_ca_endpoint.go
connect_ca_endpoint_test.go
context.go
context_test.go
coordinate_endpoint.go
coordinate_endpoint_test.go
discovery_chain_endpoint.go
discovery_chain_endpoint_test.go
enterprise_client_oss.go
enterprise_config_oss.go
enterprise_server_oss.go
enterprise_server_oss_test.go
federation_state_endpoint.go
federation_state_endpoint_test.go
federation_state_replication.go
federation_state_replication_test.go
filter.go
filter_test.go
flood.go
fsm_data_store.go
gateway_locator.go
gateway_locator_test.go
grpc_integration_test.go
health_endpoint.go
health_endpoint_test.go
helper_test.go
intention_endpoint.go
intention_endpoint_test.go
internal_endpoint.go
internal_endpoint_test.go
issue_test.go
kvs_endpoint.go
kvs_endpoint_test.go
leader.go
leader_connect.go
leader_connect_ca.go
leader_connect_ca_test.go
leader_connect_test.go
leader_federation_state_ae.go
leader_federation_state_ae_test.go
leader_intentions.go
leader_intentions_oss.go
leader_intentions_oss_test.go
leader_intentions_test.go
leader_log_verification.go
leader_metrics.go
leader_oss_test.go
leader_peering.go
leader_peering_test.go
leader_test.go
logging.go
logging_test.go
merge.go
merge_oss.go
merge_oss_test.go
merge_test.go
operator_autopilot_endpoint.go
operator_autopilot_endpoint_test.go
operator_backend.go
operator_backend_test.go
operator_endpoint.go
operator_raft_endpoint.go
operator_raft_endpoint_test.go
operator_usage_endpoint.go
options.go
options_oss.go
peering_backend.go
peering_backend_oss.go
peering_backend_oss_test.go
peering_backend_test.go
prepared_query_endpoint.go
prepared_query_endpoint_test.go
raft_rpc.go
replication.go
replication_test.go
rpc.go
rpc_test.go
rtt.go
rtt_test.go
segment_oss.go
serf_filter.go
serf_test.go
server.go
server_connect.go
server_log_verification.go
server_lookup.go
server_lookup_test.go
server_oss.go
server_overview.go
server_overview_test.go
server_register.go
server_serf.go
server_test.go
session_endpoint.go
session_endpoint_test.go
session_timers.go
session_timers_test.go
session_ttl.go
session_ttl_test.go
snapshot_endpoint.go
snapshot_endpoint_test.go
stats_fetcher.go
stats_fetcher_test.go
status_endpoint.go
status_endpoint_test.go
subscribe_backend.go
subscribe_backend_test.go
system_metadata.go
system_metadata_test.go
txn_endpoint.go
txn_endpoint_test.go
util.go
util_test.go