Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ derivative = "2.2.0"
http = "1.0.0"
log = "0.4"
h2 = ">=0.4.11"
once_cell = "1"
lru = "0.14"
ahash = ">=0.8.9"

Expand Down
2 changes: 1 addition & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
msrv = "1.72"
msrv = "1.83"
4 changes: 1 addition & 3 deletions pingora-boringssl/src/boring_tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,7 @@ where
return Poll::Pending;
}
Err(e) => {
return Poll::Ready(Err(e
.into_io_error()
.unwrap_or_else(|e| io::Error::new(io::ErrorKind::Other, e))));
return Poll::Ready(Err(e.into_io_error().unwrap_or_else(io::Error::other)));
}
}

Expand Down
1 change: 0 additions & 1 deletion pingora-cache/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ pingora-lru = { version = "0.6.0", path = "../pingora-lru" }
pingora-timeout = { version = "0.6.0", path = "../pingora-timeout" }
http = { workspace = true }
indexmap = "1"
once_cell = { workspace = true }
regex = "1"
blake2 = "0.10"
serde = { version = "1.0", features = ["derive"] }
Expand Down
6 changes: 3 additions & 3 deletions pingora-cache/src/cache_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ use super::*;
use http::header::HeaderName;
use http::HeaderValue;
use indexmap::IndexMap;
use once_cell::sync::Lazy;
use pingora_error::{Error, ErrorType};
use regex::bytes::Regex;
use std::num::IntErrorKind;
use std::slice;
use std::str;
use std::sync::LazyLock;

/// The max delta-second per [RFC 9111](https://datatracker.ietf.org/doc/html/rfc9111#section-1.2.2)
// "If a cache receives a delta-seconds value
Expand Down Expand Up @@ -157,13 +157,13 @@ impl<'a> Iterator for ListValueIter<'a> {
// note the `token` implementation excludes disallowed ASCII ranges
// and disallowed delimiters: https://datatracker.ietf.org/doc/html/rfc9110#section-5.6.2
// though it does not forbid `obs-text`: %x80-FF
static RE_CACHE_DIRECTIVE: Lazy<Regex> =
static RE_CACHE_DIRECTIVE: LazyLock<Regex> =
// to break our version down further:
// `(?-u)`: unicode support disabled, which puts the regex into "ASCII compatible mode" for specifying literal bytes like \x7F: https://docs.rs/regex/1.10.4/regex/bytes/index.html#syntax
// `(?:^|(?:\s*[,;]\s*)`: allow either , or ; as a delimiter
// `([^\x00-\x20\(\)<>@,;:\\"/\[\]\?=\{\}\x7F]+)`: token (directive name capture group)
// `(?:=((?:[^\x00-\x20\(\)<>@,;:\\"/\[\]\?=\{\}\x7F]+|(?:"(?:[^"\\]|\\.)*"))))`: token OR quoted-string (directive value capture-group)
Lazy::new(|| {
LazyLock::new(|| {
Regex::new(r#"(?-u)(?:^|(?:\s*[,;]\s*))([^\x00-\x20\(\)<>@,;:\\"/\[\]\?=\{\}\x7F]+)(?:=((?:[^\x00-\x20\(\)<>@,;:\\"/\[\]\?=\{\}\x7F]+|(?:"(?:[^"\\]|\\.)*"))))?"#).unwrap()
});

Expand Down
2 changes: 1 addition & 1 deletion pingora-cache/src/eviction/simple_lru.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl Manager {
if self.used.load(Ordering::Relaxed) <= self.limit
&& self
.items_watermark
.map_or(true, |w| self.items.load(Ordering::Relaxed) <= w)
.is_none_or(|w| self.items.load(Ordering::Relaxed) <= w)
{
return vec![];
}
Expand Down
2 changes: 1 addition & 1 deletion pingora-cache/src/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub fn calculate_fresh_until(
if authorization_present {
let uncacheable = cache_control
.as_ref()
.map_or(true, |cc| !cc.allow_caching_authorized_req());
.is_none_or(|cc| !cc.allow_caching_authorized_req());
if uncacheable {
return None;
}
Expand Down
2 changes: 1 addition & 1 deletion pingora-cache/src/hashtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ where
pub fn new(shard_capacity: usize) -> Self {
use std::num::NonZeroUsize;
// safe, 1 != 0
const ONE: NonZeroUsize = unsafe { NonZeroUsize::new_unchecked(1) };
const ONE: NonZeroUsize = NonZeroUsize::new(1).unwrap();
let mut cache = ConcurrentLruCache {
lrus: Default::default(),
};
Expand Down
2 changes: 1 addition & 1 deletion pingora-cache/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ impl HttpCache {
self.inner_mut()
.max_file_size_tracker
.as_mut()
.map_or(true, |t| t.add_body_bytes(bytes_len))
.is_none_or(|t| t.add_body_bytes(bytes_len))
}

/// Check if the max file size has been exceeded according to max file size tracker.
Expand Down
12 changes: 6 additions & 6 deletions pingora-cache/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ impl Storage for MemCache {
mod test {
use super::*;
use cf_rustracing::span::Span;
use once_cell::sync::Lazy;
use std::sync::LazyLock;

fn gen_meta() -> CacheMeta {
let mut header = ResponseHeader::build(200, None).unwrap();
Expand All @@ -445,7 +445,7 @@ mod test {

#[tokio::test]
async fn test_write_then_read() {
static MEM_CACHE: Lazy<MemCache> = Lazy::new(MemCache::new);
static MEM_CACHE: LazyLock<MemCache> = LazyLock::new(MemCache::new);
let span = &Span::inactive().handle();

let key1 = CacheKey::new("", "a", "1");
Expand Down Expand Up @@ -482,7 +482,7 @@ mod test {

#[tokio::test]
async fn test_read_range() {
static MEM_CACHE: Lazy<MemCache> = Lazy::new(MemCache::new);
static MEM_CACHE: LazyLock<MemCache> = LazyLock::new(MemCache::new);
let span = &Span::inactive().handle();

let key1 = CacheKey::new("", "a", "1");
Expand Down Expand Up @@ -527,7 +527,7 @@ mod test {
async fn test_write_while_read() {
use futures::FutureExt;

static MEM_CACHE: Lazy<MemCache> = Lazy::new(MemCache::new);
static MEM_CACHE: LazyLock<MemCache> = LazyLock::new(MemCache::new);
let span = &Span::inactive().handle();

let key1 = CacheKey::new("", "a", "1");
Expand Down Expand Up @@ -594,7 +594,7 @@ mod test {

#[tokio::test]
async fn test_purge_partial() {
static MEM_CACHE: Lazy<MemCache> = Lazy::new(MemCache::new);
static MEM_CACHE: LazyLock<MemCache> = LazyLock::new(MemCache::new);
let cache = &MEM_CACHE;

let key = CacheKey::new("", "a", "1").to_compact();
Expand All @@ -621,7 +621,7 @@ mod test {

#[tokio::test]
async fn test_purge_complete() {
static MEM_CACHE: Lazy<MemCache> = Lazy::new(MemCache::new);
static MEM_CACHE: LazyLock<MemCache> = LazyLock::new(MemCache::new);
let cache = &MEM_CACHE;

let key = CacheKey::new("", "a", "1").to_compact();
Expand Down
6 changes: 3 additions & 3 deletions pingora-cache/src/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

pub use http::Extensions;
use log::warn;
use once_cell::sync::{Lazy, OnceCell};
use pingora_error::{Error, ErrorType::*, OrErr, Result};
use pingora_header_serde::HeaderSerde;
use pingora_http::{HMap, ResponseHeader};
use serde::{Deserialize, Serialize};
use std::borrow::Cow;
use std::sync::{LazyLock, OnceLock};
use std::time::{Duration, SystemTime};

use crate::key::HashBinary;
Expand Down Expand Up @@ -568,9 +568,9 @@ impl CacheMetaDefaults {
/// The dictionary content for header compression.
///
/// Used during initialization of [`HEADER_SERDE`].
static COMPRESSION_DICT_CONTENT: OnceCell<Cow<'static, [u8]>> = OnceCell::new();
static COMPRESSION_DICT_CONTENT: OnceLock<Cow<'static, [u8]>> = OnceLock::new();

static HEADER_SERDE: Lazy<HeaderSerde> = Lazy::new(|| {
static HEADER_SERDE: LazyLock<HeaderSerde> = LazyLock::new(|| {
let dict_opt = if let Some(dict_content) = COMPRESSION_DICT_CONTENT.get() {
Some(dict_content.to_vec())
} else {
Expand Down
4 changes: 2 additions & 2 deletions pingora-cache/src/put.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ impl<C: CachePut> CachePutCtx<C> {
mod test {
use super::*;
use cf_rustracing::span::Span;
use once_cell::sync::Lazy;
use std::sync::LazyLock;

struct TestCachePut();
impl CachePut for TestCachePut {
Expand All @@ -227,7 +227,7 @@ mod test {
}

type TestCachePutCtx = CachePutCtx<TestCachePut>;
static CACHE_BACKEND: Lazy<MemCache> = Lazy::new(MemCache::new);
static CACHE_BACKEND: LazyLock<MemCache> = LazyLock::new(MemCache::new);

#[tokio::test]
async fn test_cache_put() {
Expand Down
1 change: 0 additions & 1 deletion pingora-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ log = { workspace = true }
h2 = { workspace = true }
derivative.workspace = true
clap = { version = "3.2.25", features = ["derive"] }
once_cell = { workspace = true }
serde = { version = "1.0", features = ["derive"] }
serde_yaml = "0.8"
strum = "0.26.2"
Expand Down
2 changes: 1 addition & 1 deletion pingora-core/src/connectors/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Connector {
// We assume no peer option == no ALPN == h1 only
let h1_only = peer
.get_peer_options()
.map_or(true, |o| o.alpn.get_max_http_version() == 1);
.is_none_or(|o| o.alpn.get_max_http_version() == 1);
if h1_only {
let (h1, reused) = self.h1.get_http_session(peer).await?;
Ok((HttpSession::H1(h1), reused))
Expand Down
2 changes: 1 addition & 1 deletion pingora-core/src/connectors/http/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ impl Connector {
if peer.tls()
|| peer
.get_peer_options()
.map_or(true, |o| o.alpn.get_min_http_version() == 1)
.is_none_or(|o| o.alpn.get_min_http_version() == 1)
{
return Ok(HttpSession::H1(Http1Session::new(stream)));
}
Expand Down
5 changes: 4 additions & 1 deletion pingora-core/src/connectors/l4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,23 +307,26 @@ async fn proxy_connect<P: Peer>(peer: &P) -> Result<Stream> {
mod tests {
use super::*;
use crate::upstreams::peer::{BasicPeer, HttpPeer, Proxy};
#[cfg(target_os = "linux")]
use pingora_error::ErrorType;
use std::collections::BTreeMap;
use std::path::PathBuf;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
#[cfg(target_os = "linux")]
use std::time::{Duration, Instant};
use tokio::io::AsyncWriteExt;
#[cfg(unix)]
use tokio::net::UnixListener;
#[cfg(target_os = "linux")]
use tokio::time::sleep;

/// Some of the tests below are flaky when making new connections to mock
/// servers. The servers are simple tokio listeners, so failures there are
/// not indicative of real errors. This function will retry the peer/server
/// in increasing intervals until it either succeeds in connecting or a long
/// timeout expires (max 10sec)
#[cfg(unix)]
#[cfg(target_os = "linux")]
async fn wait_for_peer<P>(peer: &P)
where
P: Peer + Send + Sync,
Expand Down
6 changes: 3 additions & 3 deletions pingora-core/src/connectors/offload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
// limitations under the License.

use log::debug;
use once_cell::sync::OnceCell;
use rand::Rng;
use std::sync::OnceLock;
use tokio::runtime::{Builder, Handle};
use tokio::sync::oneshot::{channel, Sender};

Expand All @@ -25,7 +25,7 @@ pub(crate) struct OffloadRuntime {
thread_per_shard: usize,
// Lazily init the runtimes so that they are created after pingora
// daemonize itself. Otherwise the runtime threads are lost.
pools: OnceCell<Box<[(Handle, Sender<()>)]>>,
pools: OnceLock<Box<[(Handle, Sender<()>)]>>,
}

impl OffloadRuntime {
Expand All @@ -35,7 +35,7 @@ impl OffloadRuntime {
OffloadRuntime {
shards,
thread_per_shard,
pools: OnceCell::new(),
pools: OnceLock::new(),
}
}

Expand Down
6 changes: 3 additions & 3 deletions pingora-core/src/modules/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ pub mod grpc_web;
use async_trait::async_trait;
use bytes::Bytes;
use http::HeaderMap;
use once_cell::sync::OnceCell;
use pingora_error::Result;
use pingora_http::{RequestHeader, ResponseHeader};
use std::any::Any;
use std::any::TypeId;
use std::collections::HashMap;
use std::sync::Arc;
use std::sync::OnceLock;

/// The trait an HTTP traffic module needs to implement
#[async_trait]
Expand Down Expand Up @@ -101,15 +101,15 @@ pub type ModuleBuilder = Box<dyn HttpModuleBuilder + 'static + Send + Sync>;
/// The object to hold multiple http modules
pub struct HttpModules {
modules: Vec<ModuleBuilder>,
module_index: OnceCell<Arc<HashMap<TypeId, usize>>>,
module_index: OnceLock<Arc<HashMap<TypeId, usize>>>,
}

impl HttpModules {
/// Create a new [HttpModules]
pub fn new() -> Self {
HttpModules {
modules: vec![],
module_index: OnceCell::new(),
module_index: OnceLock::new(),
}
}

Expand Down
20 changes: 10 additions & 10 deletions pingora-core/src/protocols/digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use std::sync::Arc;
use std::time::{Duration, SystemTime};

use once_cell::sync::OnceCell;
use std::sync::OnceLock;

use super::l4::ext::{get_original_dest, get_recv_buf, get_snd_buf, get_tcp_info, TCP_INFO};
use super::l4::socket::SocketAddr;
Expand Down Expand Up @@ -67,31 +67,31 @@ pub struct SocketDigest {
#[cfg(windows)]
raw_sock: std::os::windows::io::RawSocket,
/// Remote socket address
pub peer_addr: OnceCell<Option<SocketAddr>>,
pub peer_addr: OnceLock<Option<SocketAddr>>,
/// Local socket address
pub local_addr: OnceCell<Option<SocketAddr>>,
pub local_addr: OnceLock<Option<SocketAddr>>,
/// Original destination address
pub original_dst: OnceCell<Option<SocketAddr>>,
pub original_dst: OnceLock<Option<SocketAddr>>,
}

impl SocketDigest {
#[cfg(unix)]
pub fn from_raw_fd(raw_fd: std::os::unix::io::RawFd) -> SocketDigest {
SocketDigest {
raw_fd,
peer_addr: OnceCell::new(),
local_addr: OnceCell::new(),
original_dst: OnceCell::new(),
peer_addr: OnceLock::new(),
local_addr: OnceLock::new(),
original_dst: OnceLock::new(),
}
}

#[cfg(windows)]
pub fn from_raw_socket(raw_sock: std::os::windows::io::RawSocket) -> SocketDigest {
SocketDigest {
raw_sock,
peer_addr: OnceCell::new(),
local_addr: OnceCell::new(),
original_dst: OnceCell::new(),
peer_addr: OnceLock::new(),
local_addr: OnceLock::new(),
original_dst: OnceLock::new(),
}
}

Expand Down
4 changes: 2 additions & 2 deletions pingora-core/src/protocols/http/compression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,12 +616,12 @@ fn test_decide_action() {
assert_eq!(decide_action(&header, &[Brotli, Gzip]), Noop);
}

use once_cell::sync::Lazy;
use regex::Regex;
use std::sync::LazyLock;

// Allow text, application, font, a few image/ MIME types and binary/octet-stream
// TODO: fine tune this list
static MIME_CHECK: Lazy<Regex> = Lazy::new(|| {
static MIME_CHECK: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(r"^(?:text/|application/|font/|image/(?:x-icon|svg\+xml|nd\.microsoft\.icon)|binary/octet-stream)")
.unwrap()
});
Expand Down
6 changes: 3 additions & 3 deletions pingora-core/src/protocols/http/error_resp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
//! Error response generating utilities.

use http::header;
use once_cell::sync::Lazy;
use pingora_http::ResponseHeader;
use std::sync::LazyLock;

use super::SERVER_NAME;

Expand All @@ -36,6 +36,6 @@ pub fn gen_error_response(code: u16) -> ResponseHeader {
}

/// Pre-generated 502 response
pub static HTTP_502_RESPONSE: Lazy<ResponseHeader> = Lazy::new(|| gen_error_response(502));
pub static HTTP_502_RESPONSE: LazyLock<ResponseHeader> = LazyLock::new(|| gen_error_response(502));
/// Pre-generated 400 response
pub static HTTP_400_RESPONSE: Lazy<ResponseHeader> = Lazy::new(|| gen_error_response(400));
pub static HTTP_400_RESPONSE: LazyLock<ResponseHeader> = LazyLock::new(|| gen_error_response(400));
Loading