Skip to content

Commit a62eb14

Browse files
committed
fix: runtime panic - Registering a blocking socket with tokio runtime is unsupported
thread 'tokio-runtime-worker' panicked at /home/josecelano/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/axum-server-0.8.0/src/server.rs:70:30: Registering a blocking socket with the tokio runtime is unsupported. If you wish to do anyways, please add `--cfg tokio_allow_from_blocking_fd` to your RUSTFLAGS. See github.com/tokio-rs/tokio/issues/7172 for details. Set std::net::TcpListener instances to non-blocking mode using set_nonblocking(true) before passing them to axum-server to avoid runtime panics when registering with tokio runtime. This is required since axum-server 0.8.0 and tokio v1.44.0 which added debug assertions to prevent blocking sockets from being registered with the tokio runtime.
1 parent 02e4339 commit a62eb14

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

packages/axum-health-check-api-server/src/server.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ pub fn start(
101101
.layer(SetRequestIdLayer::x_request_id(MakeRequestUuid));
102102

103103
let socket = std::net::TcpListener::bind(bind_to).expect("Could not bind tcp_listener to address.");
104+
socket
105+
.set_nonblocking(true)
106+
.expect("Failed to set socket to non-blocking mode");
104107
let address = socket.local_addr().expect("Could not get local_addr from tcp_listener.");
105108
let protocol = Protocol::HTTP; // The health check API only supports HTTP directly now. Use a reverse proxy for HTTPS.
106109
let service_binding = ServiceBinding::new(protocol.clone(), address).expect("Service binding creation failed");

packages/axum-http-tracker-server/src/server.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ impl Launcher {
5252
rx_halt: Receiver<Halted>,
5353
) -> BoxFuture<'static, ()> {
5454
let socket = std::net::TcpListener::bind(self.bind_to).expect("Could not bind tcp_listener to address.");
55+
socket
56+
.set_nonblocking(true)
57+
.expect("Failed to set socket to non-blocking mode");
5558
let address = socket.local_addr().expect("Could not get local_addr from tcp_listener.");
5659

5760
let handle = Handle::new();

packages/axum-rest-tracker-api-server/src/server.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ impl Launcher {
247247
rx_halt: Receiver<Halted>,
248248
) -> BoxFuture<'static, ()> {
249249
let socket = std::net::TcpListener::bind(self.bind_to).expect("Could not bind tcp_listener to address.");
250+
socket.set_nonblocking(true).expect("Failed to set socket to non-blocking mode");
250251
let address = socket.local_addr().expect("Could not get local_addr from tcp_listener.");
251252

252253
let router = router(http_api_container, access_tokens, address);

0 commit comments

Comments
 (0)