mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-27 10:18:54 +00:00
refactor(connlib): use RwLock for feature flags (#8397)
Most of the time, these flags are only read from and not written thus. By using a read-lock, we make sure that even when we use feature-flags from multiple threads, they don't cause any contention.
This commit is contained in:
@@ -7,7 +7,7 @@ use std::{
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use env::ON_PREM;
|
||||
use parking_lot::Mutex;
|
||||
use parking_lot::RwLock;
|
||||
use sentry::protocol::SessionStatus;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -31,7 +31,7 @@ const POSTHOG_API_KEY: &str = "phc_uXXl56plyvIBHj81WwXBLtdPElIRbm7keRTdUCmk8ll";
|
||||
// Process-wide storage of enabled feature flags.
|
||||
//
|
||||
// Defaults to everything off.
|
||||
static FEATURE_FLAGS: LazyLock<Mutex<FeatureFlags>> = LazyLock::new(Mutex::default);
|
||||
static FEATURE_FLAGS: LazyLock<RwLock<FeatureFlags>> = LazyLock::new(RwLock::default);
|
||||
|
||||
/// Exposes all feature flags as public, static functions.
|
||||
///
|
||||
@@ -40,7 +40,7 @@ pub mod feature_flags {
|
||||
use crate::*;
|
||||
|
||||
pub fn icmp_unreachable_instead_of_nat64() -> bool {
|
||||
FEATURE_FLAGS.lock().icmp_unreachable_instead_of_nat64
|
||||
FEATURE_FLAGS.read().icmp_unreachable_instead_of_nat64
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,7 +188,7 @@ impl Telemetry {
|
||||
|
||||
tracing::debug!(?flags, "Evaluated feature-flags");
|
||||
|
||||
*FEATURE_FLAGS.lock() = flags;
|
||||
*FEATURE_FLAGS.write() = flags;
|
||||
|
||||
sentry::Hub::main().configure_scope(|scope| {
|
||||
scope.set_context("flags", sentry_flag_context(flags));
|
||||
|
||||
Reference in New Issue
Block a user