Skip to content

Commit

Permalink
update axum/server
Browse files Browse the repository at this point in the history
  • Loading branch information
Swatinem committed Dec 29, 2023
1 parent 0912806 commit 87ab162
Show file tree
Hide file tree
Showing 13 changed files with 386 additions and 302 deletions.
578 changes: 334 additions & 244 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crates/symbolicator-crash/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ publish = false
[dependencies]

[build-dependencies]
bindgen = "0.68.1"
bindgen = "0.69.1"
cmake = { version = "0.1.46" }
2 changes: 1 addition & 1 deletion crates/symbolicator-crash/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn main() {

let bindings = bindgen::Builder::default()
.header("sentry-native/include/sentry.h")
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
.generate()
.expect("Unable to generate bindings");

Expand Down
11 changes: 9 additions & 2 deletions crates/symbolicator-js/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ humantime = "2.1.0"
moka = { version = "0.12.1", features = ["future", "sync"] }
once_cell = "1.17.1"
regex = "1.5.5"
reqwest = { version = "0.11.0", features = ["gzip", "brotli", "deflate", "json", "stream", "trust-dns"] }
sentry = { version = "0.31.7", features = ["tracing"] }
reqwest = { version = "0.11.0", features = [
"gzip",
"brotli",
"deflate",
"json",
"stream",
"trust-dns",
] }
sentry = { version = "0.32.1", features = ["tracing"] }
serde = { version = "1.0.137", features = ["derive", "rc"] }
serde_json = "1.0.81"
sha2 = "0.10.6"
Expand Down
2 changes: 1 addition & 1 deletion crates/symbolicator-native/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ minidump-unwind = "0.19.1"
moka = { version = "0.12.1", features = ["future", "sync"] }
once_cell = "1.18.0"
regex = "1.5.5"
sentry = { version = "0.31.7", features = ["tracing"] }
sentry = { version = "0.32.1", features = ["tracing"] }
serde = { version = "1.0.137", features = ["derive", "rc"] }
symbolic = { version = "12.7.1", features = ["cfi", "common-serde", "debuginfo", "demangle", "symcache", "il2cpp", "ppdb"] }
symbolicator-service = { path = "../symbolicator-service" }
Expand Down
6 changes: 3 additions & 3 deletions crates/symbolicator-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ aws-config = { version = "1.0.1", features = ["behavior-version-latest"] }
aws-credential-types = { version = "1.0.1", features = ["hardcoded-credentials"] }
aws-sdk-s3 = "1.4.0"
aws-types = "1.0.1"
cadence = "0.29.0"
cadence = "1.0.0"
chrono = { version = "0.4.19", features = ["serde"] }
filetime = "0.2.16"
flate2 = "1.0.23"
futures = "0.3.12"
gcp_auth = "0.9.0"
gcp_auth = "0.10.0"
humantime = "2.1.0"
humantime-serde = "1.1.1"
idna = "0.5.0"
Expand All @@ -29,7 +29,7 @@ moka = { version = "0.12.1", features = ["future", "sync"] }
once_cell = "1.17.1"
rand = "0.8.5"
reqwest = { version = "0.11.0", features = ["gzip", "brotli", "deflate", "json", "stream", "trust-dns"] }
sentry = { version = "0.31.7", features = ["tracing"] }
sentry = { version = "0.32.1", features = ["tracing"] }
serde = { version = "1.0.137", features = ["derive", "rc"] }
serde_json = "1.0.81"
serde_yaml = "0.9.14"
Expand Down
5 changes: 3 additions & 2 deletions crates/symbolicator-stress/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ edition = "2021"

[dependencies]
anyhow = "1.0.57"
axum = "0.6.10"
axum = "0.7.2"
axum-server = "0.6.0"
clap = { version = "4.3.2", features = ["derive"] }
futures = "0.3.12"
humantime = "2.0.1"
sentry = { version = "0.31.7", features = ["anyhow", "debug-images", "tracing"] }
sentry = { version = "0.32.1", features = ["anyhow", "debug-images", "tracing"] }
serde = { version = "1.0.137", features = ["derive"] }
serde_json = "1.0.81"
serde_yaml = "0.9.14"
Expand Down
9 changes: 5 additions & 4 deletions crates/symbolicator-stress/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ pub fn init(config: Config) -> Guard {
"OK"
}
use axum::handler::HandlerWithoutStateExt;
let server = axum::Server::from_tcp(listener)
.unwrap()
.serve(ok.into_make_service());
server.await.unwrap()

axum_server::from_tcp(listener)
.serve(ok.into_make_service())
.await
.unwrap();
}));

let dsn = format!("http://[email protected]:{}/1234", socket.port());
Expand Down
5 changes: 3 additions & 2 deletions crates/symbolicator-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ edition = "2021"
license = "MIT"

[dependencies]
axum = "0.6.10"
axum = "0.7.2"
axum-server = "0.6.0"
humantime = "2.0.1"
insta = { version = "1.18.0", features = ["redactions", "yaml"] }
regex = "1.5.5"
Expand All @@ -16,5 +17,5 @@ serde_json = "1.0.94"
symbolicator-sources = { path = "../symbolicator-sources" }
tempfile = "3.2.0"
tokio = { version = "1.26.0", features = ["rt", "macros", "fs"] }
tower-http = { version = "0.4.0", features = ["fs", "trace"] }
tower-http = { version = "0.5.0", features = ["fs", "trace"] }
tracing-subscriber = { version = "0.3.17", features = ["tracing-log", "local-time", "env-filter", "json"] }
17 changes: 10 additions & 7 deletions crates/symbolicator-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@
//! HTTP connections.
use std::collections::BTreeMap;
use std::net::SocketAddr;
use std::net::{SocketAddr, TcpListener};
use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex};

use axum::http::StatusCode;
use axum::response::{IntoResponse, Redirect};
use axum::routing::{get, get_service};
use axum::{extract, Json};
use axum::{middleware, Router};
use reqwest::{StatusCode, Url};
use reqwest::Url;
use serde::{Deserialize, Serialize};
use tokio::sync::OnceCell;
use tower_http::services::ServeDir;
Expand Down Expand Up @@ -179,7 +180,7 @@ impl Server {

let hitcounter = {
let hits = hits.clone();
move |extract::OriginalUri(uri), req, next: middleware::Next<_>| {
move |extract::OriginalUri(uri), req, next: middleware::Next| {
let hits = hits.clone();
async move {
{
Expand All @@ -196,12 +197,14 @@ impl Server {
let router = router.layer(middleware::from_fn(hitcounter));

let addr = SocketAddr::from(([127, 0, 0, 1], 0));

let server = axum::Server::bind(&addr).serve(router.into_make_service());
let socket = server.local_addr();
let listener = TcpListener::bind(addr).unwrap();
let socket = listener.local_addr().unwrap();

let handle = tokio::spawn(async move {
server.await.unwrap();
axum_server::from_tcp(listener)
.serve(router.into_make_service())
.await
.unwrap();
});

Self {
Expand Down
6 changes: 3 additions & 3 deletions crates/symbolicator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ https = ["axum-server/tls-rustls", "symbolicator-service/https"]

[dependencies]
anyhow = "1.0.57"
axum = { version = "0.6.10", features = ["multipart"] }
axum-server = "0.5.1"
axum = { version = "0.7.2", features = ["multipart"] }
axum-server = "0.6.0"
clap = { version = "4.3.2", features = ["derive"] }
console = "0.15.0"
futures = "0.3.12"
hostname = "0.3.1"
sentry = { version = "0.31.7", features = ["anyhow", "debug-images", "tracing", "tower", "tower-http"] }
sentry = { version = "0.32.1", features = ["anyhow", "debug-images", "tracing", "tower", "tower-http"] }
serde = { version = "1.0.137", features = ["derive", "rc"] }
serde_json = "1.0.81"
symbolic = "12.7.1"
Expand Down
2 changes: 1 addition & 1 deletion crates/symbolicator/src/endpoints/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub async fn proxy_symstore_request(
}

let bytes = Cursor::new(data);
Ok(response.body(Body::wrap_stream(tokio_util::io::ReaderStream::new(bytes)))?)
Ok(response.body(Body::from_stream(tokio_util::io::ReaderStream::new(bytes)))?)
}

#[cfg(test)]
Expand Down
43 changes: 12 additions & 31 deletions crates/symbolicator/src/server.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use axum_server::Handle;
#[cfg(feature = "https")]
use std::fs::read;
use std::net::SocketAddr;
use std::net::TcpListener;
#[cfg(feature = "https")]
use std::path::PathBuf;

Expand Down Expand Up @@ -56,50 +56,31 @@ pub fn run(config: Config) -> Result<()> {

let svc = endpoints::create_app(service).into_make_service();

let handle_http = Handle::new();
let socket_http = config.bind.parse::<SocketAddr>()?;
let socket_http = TcpListener::bind(config.bind.parse::<SocketAddr>()?)?;
let local_addr = socket_http.local_addr()?;
tracing::info!("Starting HTTP server on {}", local_addr);

#[allow(clippy::redundant_clone)] // we need `svc` for the https case below
let server_http = axum_server::bind(socket_http)
.handle(handle_http.clone())
.serve(svc.clone());
let server_http = axum_server::from_tcp(socket_http).serve(svc.clone());
servers.push(Box::pin(server_http));

let listening_http = async move {
if let Some(local_addr) = handle_http.listening().await {
tracing::info!("Starting HTTP server on {}", local_addr);
} else {
panic!("Unable to listen on HTTP port");
}
Ok(())
};
servers.push(Box::pin(listening_http));

#[cfg(feature = "https")]
if let Some(ref bind_str) = config.bind_https {
let handle_https = Handle::new();
let https_conf = match config.server_config.https {
None => panic!("Need HTTPS config"),
Some(ref conf) => conf,
};
let socket_https = bind_str.parse::<SocketAddr>()?;
let socket_https = TcpListener::bind(bind_str.parse::<SocketAddr>()?)?;
let local_addr = socket_https.local_addr()?;
tracing::info!("Starting HTTPS server on {}", local_addr);

let certificate = read_pem_file(&https_conf.certificate_path)?;
let key = read_pem_file(&https_conf.key_path)?;
let tls_config =
web_pool.block_on(async { RustlsConfig::from_pem(certificate, key).await })?;
let server_https = axum_server::bind_rustls(socket_https, tls_config)
.handle(handle_https.clone())
.serve(svc);
servers.push(Box::pin(server_https));

let listening_https = async move {
if let Some(local_addr) = handle_https.listening().await {
tracing::info!("Starting HTTPS server on {}", local_addr);
} else {
panic!("Unable to listen on HTTPS port");
}
Ok(())
};
servers.push(Box::pin(listening_https));
let server_https = axum_server::from_tcp_rustls(socket_https, tls_config).serve(svc);
servers.push(Box::pin(server_https));
}

web_pool.block_on(try_join_all(servers))?;
Expand Down

0 comments on commit 87ab162

Please sign in to comment.