Skip to content

Commit 23397cf

Browse files
committed
Merge #9: fix: set TcpListener to non-blocking mode before passing to axum-server
8cdb2d9 fix: set TcpListener to non-blocking mode before passing to axum-server (Jose Celano) Pull request description: ## Description This PR fixes the Tokio runtime panic that occurs when running the application with `cargo run`. ## Problem The application was panicking with: ``` 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. ``` ## Root Cause - Tokio 1.44.0 introduced stricter validation to prevent blocking file descriptors from being registered with the async runtime - `std::net::TcpListener::bind()` creates blocking sockets by default - axum-server 0.8.0 internally uses `tokio::net::TcpListener::from_std()` which panics when it detects a blocking socket ## Solution Set the `TcpListener` to non-blocking mode **before** passing it to axum-server by calling `socket.set_nonblocking(true)` immediately after binding. ## Changes - ✅ Added `socket.set_nonblocking(true)` in `src/api/mod.rs` after binding the TcpListener - ✅ Removed the incorrect RUSTFLAGS workaround from README.md troubleshooting section - ✅ Deleted temporary TOKIO_BLOCKING_SOCKET_FIX.md file ## Benefits - Proper fix instead of masking the symptom with RUSTFLAGS - Prevents potential performance issues under load - Application now runs correctly with just `cargo run` ## Testing Verified that the application starts successfully without any panic: ```bash cargo run ``` Fixes #8 ## References - [Tokio Issue #7172](tokio-rs/tokio#7172) - [Tokio PR #7166](tokio-rs/tokio#7166) ACKs for top commit: josecelano: ACK 8cdb2d9 Tree-SHA512: 12653e0a924f03fb6e43d9eb381aec6e593227f2a095ba681b952c3851ed09575a2a5cbca2b0fd6d0647d9c777d4a28418bc51e768568f618457614c34b02b15
2 parents cb53762 + 8cdb2d9 commit 23397cf

File tree

2 files changed

+4
-16
lines changed

2 files changed

+4
-16
lines changed

README.md

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,6 @@ You can check the API with the health_check endpoint: <http://127.0.0.1:3000/hea
4545

4646
## Troubleshooting
4747

48-
### Tokio Runtime Error
49-
50-
If you encounter an error like:
51-
52-
```text
53-
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.
54-
```
55-
56-
You need to set the RUSTFLAGS environment variable when building and running the application:
57-
58-
```console
59-
RUSTFLAGS="--cfg tokio_allow_from_blocking_fd" cargo run
60-
```
61-
62-
This is a known issue with the tokio runtime on certain systems. The flag allows the application to register blocking file descriptors with the async runtime.
63-
6448
### Session Directory Not Found
6549

6650
If you see an error about the session output directory not being found:

src/api/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ pub async fn start(bind_to: &SocketAddr, state: AppState) {
3434
let socket =
3535
std::net::TcpListener::bind(bind_to).expect("Could not bind tcp_listener to address.");
3636

37+
socket
38+
.set_nonblocking(true)
39+
.expect("Failed to set socket to non-blocking mode");
40+
3741
let server_address = socket
3842
.local_addr()
3943
.expect("Could not get local_addr from tcp_listener.");

0 commit comments

Comments
 (0)