programatik29 / axum-server

High level server designed to be used with axum framework.
MIT License
177 stars 63 forks source link

Reuse_addr / Clean shutdown #53

Closed FredrikNoren closed 2 years ago

FredrikNoren commented 2 years ago

Hi,

I'm building a server which auto updates, but when it restarts I get "address in use" exceptions. As far as I can tell from https://github.com/hyperium/hyper/issues/1575 I need to set reuse_addr, but I can't seem to find a way to do it through axum_server. Any chance it could be added? (I'm also using rustls).

FredrikNoren commented 2 years ago

For anyone else running into this; here's how it can be done in 0.4.2 (using socket2):

let addr = SocketAddr::from(([127, 0, 0, 1], 8080));
let socket = Socket::new(Domain::IPV4, Type::STREAM, None)?;
socket.set_reuse_address(true)?;
socket.bind(&addr.into())?;
socket.listen(128)?;
let listener: TcpListener = socket.into();
axum_server::from_tcp(listener)