Commit 23397cf
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: 12653e0a924f03fb6e43d9eb381aec6e593227f2a095ba681b952c3851ed09575a2a5cbca2b0fd6d0647d9c777d4a28418bc51e768568f618457614c34b02b152 files changed
+4
-16
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | 48 | | |
65 | 49 | | |
66 | 50 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
37 | 41 | | |
38 | 42 | | |
39 | 43 | | |
| |||
0 commit comments