mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-24 13:16:28 +00:00
feat: change default listen to IPv4 and add panic recovery (#36)
This commit is contained in:
Generated
+1
@@ -10085,6 +10085,7 @@ dependencies = [
|
|||||||
"futures-util",
|
"futures-util",
|
||||||
"http 1.3.1",
|
"http 1.3.1",
|
||||||
"http-body 1.0.1",
|
"http-body 1.0.1",
|
||||||
|
"http-body-util",
|
||||||
"iri-string",
|
"iri-string",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
|||||||
@@ -18,10 +18,11 @@ use futures::{Stream, StreamExt};
|
|||||||
use hyper::client::conn::http2::Builder;
|
use hyper::client::conn::http2::Builder;
|
||||||
use hyper_util::rt::TokioExecutor;
|
use hyper_util::rt::TokioExecutor;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
|
use std::net::Ipv4Addr;
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashSet,
|
collections::HashSet,
|
||||||
fmt::Display,
|
fmt::Display,
|
||||||
net::{IpAddr, Ipv6Addr, SocketAddr, TcpListener, ToSocketAddrs},
|
net::{IpAddr, SocketAddr, TcpListener, ToSocketAddrs},
|
||||||
};
|
};
|
||||||
use transform_stream::AsyncTryStream;
|
use transform_stream::AsyncTryStream;
|
||||||
use url::{Host, Url};
|
use url::{Host, Url};
|
||||||
@@ -201,7 +202,7 @@ pub fn parse_and_resolve_address(addr_str: &str) -> std::io::Result<SocketAddr>
|
|||||||
} else {
|
} else {
|
||||||
port
|
port
|
||||||
};
|
};
|
||||||
SocketAddr::new(IpAddr::V6(Ipv6Addr::UNSPECIFIED), final_port)
|
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), final_port)
|
||||||
} else {
|
} else {
|
||||||
let mut addr = check_local_server_addr(addr_str)?; // assume check_local_server_addr is available here
|
let mut addr = check_local_server_addr(addr_str)?; // assume check_local_server_addr is available here
|
||||||
if addr.port() == 0 {
|
if addr.port() == 0 {
|
||||||
@@ -477,12 +478,12 @@ mod test {
|
|||||||
fn test_parse_and_resolve_address() {
|
fn test_parse_and_resolve_address() {
|
||||||
// Test port-only format
|
// Test port-only format
|
||||||
let result = parse_and_resolve_address(":8080").unwrap();
|
let result = parse_and_resolve_address(":8080").unwrap();
|
||||||
assert_eq!(result.ip(), IpAddr::V6(Ipv6Addr::UNSPECIFIED));
|
assert_eq!(result.ip(), IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)));
|
||||||
assert_eq!(result.port(), 8080);
|
assert_eq!(result.port(), 8080);
|
||||||
|
|
||||||
// Test port-only format with port 0 (should get available port)
|
// Test port-only format with port 0 (should get available port)
|
||||||
let result = parse_and_resolve_address(":0").unwrap();
|
let result = parse_and_resolve_address(":0").unwrap();
|
||||||
assert_eq!(result.ip(), IpAddr::V6(Ipv6Addr::UNSPECIFIED));
|
assert_eq!(result.ip(), IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)));
|
||||||
assert!(result.port() > 0);
|
assert!(result.port() > 0);
|
||||||
|
|
||||||
// Test localhost with port
|
// Test localhost with port
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ tower-http = { workspace = true, features = [
|
|||||||
"compression-deflate",
|
"compression-deflate",
|
||||||
"compression-gzip",
|
"compression-gzip",
|
||||||
"cors",
|
"cors",
|
||||||
|
"catch-panic",
|
||||||
] }
|
] }
|
||||||
urlencoding = { workspace = true }
|
urlencoding = { workspace = true }
|
||||||
uuid = { workspace = true }
|
uuid = { workspace = true }
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ use tokio::net::TcpListener;
|
|||||||
use tokio::signal::unix::{SignalKind, signal};
|
use tokio::signal::unix::{SignalKind, signal};
|
||||||
use tokio_rustls::TlsAcceptor;
|
use tokio_rustls::TlsAcceptor;
|
||||||
use tonic::{Request, Status, metadata::MetadataValue};
|
use tonic::{Request, Status, metadata::MetadataValue};
|
||||||
|
use tower_http::catch_panic::CatchPanicLayer;
|
||||||
use tower_http::cors::CorsLayer;
|
use tower_http::cors::CorsLayer;
|
||||||
use tower_http::trace::TraceLayer;
|
use tower_http::trace::TraceLayer;
|
||||||
use tracing::{Span, debug, error, info, instrument, warn};
|
use tracing::{Span, debug, error, info, instrument, warn};
|
||||||
@@ -336,6 +337,7 @@ async fn run(opt: config::Opt) -> Result<()> {
|
|||||||
|
|
||||||
let hybrid_service = TowerToHyperService::new(
|
let hybrid_service = TowerToHyperService::new(
|
||||||
tower::ServiceBuilder::new()
|
tower::ServiceBuilder::new()
|
||||||
|
.layer(CatchPanicLayer::new())
|
||||||
.layer(
|
.layer(
|
||||||
TraceLayer::new_for_http()
|
TraceLayer::new_for_http()
|
||||||
.make_span_with(|request: &HttpRequest<_>| {
|
.make_span_with(|request: &HttpRequest<_>| {
|
||||||
|
|||||||
Reference in New Issue
Block a user