fix: set TcpListener to non-blocking mode before passing to axum-server#9
Merged
josecelano merged 1 commit intomainfrom Dec 22, 2025
Merged
Conversation
This fixes the Tokio runtime panic that occurs when running the application with cargo run. The panic was caused by passing a blocking socket to axum-server, which internally uses tokio::net::TcpListener::from_std() that validates the socket is non-blocking. Changes: - Added socket.set_nonblocking(true) in src/api/mod.rs after binding - Removed incorrect RUSTFLAGS workaround from README.md troubleshooting - Deleted temporary TOKIO_BLOCKING_SOCKET_FIX.md file This is the proper fix as opposed to using RUSTFLAGS workaround which only masks the symptom and can cause performance issues under load. Fixes #8
Member
Author
|
ACK 8cdb2d9 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes the Tokio runtime panic that occurs when running the application with
cargo run.Problem
The application was panicking with:
Root Cause
std::net::TcpListener::bind()creates blocking sockets by defaulttokio::net::TcpListener::from_std()which panics when it detects a blocking socketSolution
Set the
TcpListenerto non-blocking mode before passing it to axum-server by callingsocket.set_nonblocking(true)immediately after binding.Changes
socket.set_nonblocking(true)insrc/api/mod.rsafter binding the TcpListenerBenefits
cargo runTesting
Verified that the application starts successfully without any panic:
Fixes #8
References