0.34.6_repo_cleanup
This commit is contained in:
1 parent
ce1a90397c
commit
133d2f0f91
273 files changed
+5969
-6926
No files matched your search
@@ -0,0 +1,47 @@
|
||||
mod http_invalidation_tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn default_deny_and_strict_ipv4_ipv6_cidr_validation() {
|
||||
let mut cache = Settings::default();
|
||||
assert!(!cache.permits_http_invalidation("127.0.0.1".parse().unwrap()));
|
||||
cache.http_invalidation_allowed_cidrs =
|
||||
vec!["192.0.2.42".into(), "2001:db8:10::/64".into()];
|
||||
cache.validate().unwrap();
|
||||
assert!(cache.permits_http_invalidation("192.0.2.42".parse().unwrap()));
|
||||
assert!(!cache.permits_http_invalidation("192.0.2.43".parse().unwrap()));
|
||||
assert!(cache.permits_http_invalidation("2001:db8:10::1".parse().unwrap()));
|
||||
assert!(!cache.permits_http_invalidation("2001:db8:11::1".parse().unwrap()));
|
||||
for invalid in [
|
||||
"0.0.0.0/0",
|
||||
"::/0",
|
||||
"127.0.0.1; 8.8.8.8",
|
||||
"not-an-ip",
|
||||
"10.0.0.0/33",
|
||||
] {
|
||||
cache.http_invalidation_allowed_cidrs = vec![invalid.into()];
|
||||
assert!(cache.validate().is_err(), "must reject {invalid}");
|
||||
}
|
||||
cache.http_invalidation_allowed_cidrs = vec!["192.0.2.42".into(), "192.0.2.42/32".into()];
|
||||
assert!(cache.validate().is_err(), "duplicate ranges");
|
||||
let old: Settings = serde_json::from_value(serde_json::json!({})).unwrap();
|
||||
assert!(old.http_invalidation_allowed_cidrs.is_empty());
|
||||
}
|
||||
#[test]
|
||||
fn url_qualified_invalidation_matches_only_the_requested_scheme_and_host() {
|
||||
let requested = InvalidationRequest {
|
||||
operation: InvalidationOperation::Purge,
|
||||
selector: InvalidationSelector::Exact,
|
||||
value: "https://a.example/a?v=1".into(),
|
||||
host: Some("a.example".into()),
|
||||
vhost: Some("frontend-1".into()),
|
||||
ttl_seconds: None,
|
||||
confirm_wide: false,
|
||||
};
|
||||
let matcher = normalized_matcher(&requested).unwrap();
|
||||
assert_eq!(matcher.value, "/a?v=1");
|
||||
assert_eq!(matcher.scheme.as_deref(), Some("https"));
|
||||
assert!(host_matches(&matcher, "https", "a.example", "a.example"));
|
||||
assert!(!host_matches(&matcher, "http", "a.example", "a.example"));
|
||||
assert!(!host_matches(&matcher, "https", "b.example", "b.example"));
|
||||
}
|
||||
}
|
||||
Vendored
+12
-19
@@ -6,7 +6,8 @@ impl Cache {
|
||||
let now = SystemTime::now();
|
||||
let mut bans = self.bans.lock().unwrap_or_else(|e| e.into_inner());
|
||||
bans.retain(|rule| !rule.expired(now));
|
||||
self.ban_rule_count.store(bans.len() as u64, Ordering::Release);
|
||||
self.ban_rule_count
|
||||
.store(bans.len() as u64, Ordering::Release);
|
||||
bans.clone()
|
||||
}
|
||||
|
||||
@@ -17,7 +18,8 @@ impl Cache {
|
||||
let now = SystemTime::now();
|
||||
let mut bans = self.bans.lock().unwrap_or_else(|e| e.into_inner());
|
||||
bans.retain(|rule| !rule.expired(now));
|
||||
self.ban_rule_count.store(bans.len() as u64, Ordering::Release);
|
||||
self.ban_rule_count
|
||||
.store(bans.len() as u64, Ordering::Release);
|
||||
let banned = bans.iter().any(|rule| rule.matches_hot(key, entry, now));
|
||||
if banned {
|
||||
self.counters.ban_matches.fetch_add(1, Ordering::Relaxed);
|
||||
@@ -32,7 +34,8 @@ impl Cache {
|
||||
let now = SystemTime::now();
|
||||
let mut bans = self.bans.lock().unwrap_or_else(|e| e.into_inner());
|
||||
bans.retain(|rule| !rule.expired(now));
|
||||
self.ban_rule_count.store(bans.len() as u64, Ordering::Release);
|
||||
self.ban_rule_count
|
||||
.store(bans.len() as u64, Ordering::Release);
|
||||
let banned = bans.iter().any(|rule| rule.matches_cold(key, entry, now));
|
||||
if banned {
|
||||
self.counters.ban_matches.fetch_add(1, Ordering::Relaxed);
|
||||
@@ -47,7 +50,8 @@ impl Cache {
|
||||
let now = SystemTime::now();
|
||||
let mut bans = self.bans.lock().unwrap_or_else(|e| e.into_inner());
|
||||
bans.retain(|rule| !rule.expired(now));
|
||||
self.ban_rule_count.store(bans.len() as u64, Ordering::Release);
|
||||
self.ban_rule_count
|
||||
.store(bans.len() as u64, Ordering::Release);
|
||||
bans.iter().any(|rule| rule.matches_hot(key, entry, now))
|
||||
}
|
||||
|
||||
@@ -60,7 +64,8 @@ impl Cache {
|
||||
let before = bans.len();
|
||||
bans.retain(|rule| rule.id != id);
|
||||
let removed = bans.len() != before;
|
||||
self.ban_rule_count.store(bans.len() as u64, Ordering::Release);
|
||||
self.ban_rule_count
|
||||
.store(bans.len() as u64, Ordering::Release);
|
||||
if removed {
|
||||
self.counters.bans_removed.fetch_add(1, Ordering::Relaxed);
|
||||
}
|
||||
@@ -97,7 +102,8 @@ impl Cache {
|
||||
created_at: now,
|
||||
expires_at: now.checked_add(Duration::from_secs(ttl)).unwrap_or(now),
|
||||
});
|
||||
self.ban_rule_count.store(bans.len() as u64, Ordering::Release);
|
||||
self.ban_rule_count
|
||||
.store(bans.len() as u64, Ordering::Release);
|
||||
self.counters.bans_created.fetch_add(1, Ordering::Relaxed);
|
||||
Ok(InvalidationResult {
|
||||
operation: request.operation,
|
||||
@@ -112,22 +118,9 @@ impl Cache {
|
||||
})
|
||||
}
|
||||
InvalidationOperation::Purge => {
|
||||
// A selective purge is also a publication barrier for every fill that
|
||||
// started before this operation. Existing unrelated objects remain
|
||||
// reusable, but an old in-flight response cannot repopulate a target
|
||||
// that was not yet identifiable (for example Cache-Tag before headers).
|
||||
{
|
||||
let mut store = self.store.lock().unwrap_or_else(|e| e.into_inner());
|
||||
store.generation = store.generation.wrapping_add(1);
|
||||
// This global publication barrier invalidates every older
|
||||
// ticket and pending COLD demotion. Per-key generations only
|
||||
// need to cover the current purge, not every key ever
|
||||
// purged over the lifetime of the process. Without clearing
|
||||
// them, repeated PURGEs of distinct URLs grow this map
|
||||
// indefinitely even after the objects have been evicted.
|
||||
// Release an unusually large index's backing allocation
|
||||
// after mass invalidations instead of retaining its peak
|
||||
// bucket capacity for the rest of the process lifetime.
|
||||
if store.key_generations.capacity() > 256 {
|
||||
store.key_generations = Default::default();
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user