-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
Is your feature request related to a problem? Please describe.
I lost about 6 hours tracking down a deadlock bug that ended up leading me to this in TcpListener::from_std
:
tokio/tokio/src/net/tcp/listener.rs
Lines 206 to 209 in 88445e7
/// The caller is responsible for ensuring that the listener is in | |
/// non-blocking mode. Otherwise all I/O operations on the listener | |
/// will block the thread, which will cause unexpected behavior. | |
/// Non-blocking mode can be set using [`set_nonblocking`]. |
I would argue that this API is very prone to misuse, especially since going through it is the only way to attempt binding an address outside of tokio then turn it into a tokio-usable one (even in the context of hyper/axum).
Describe the solution you'd like
I'd like the public API for this feature of converting from STD to tokio to make the necessary std_listener.set_nonblocking(true)
call.
Alternately, I think if we have a function that does not make that call, it should be named in a way that makes it explicit that the user has to do that specific thing that's not enforced by typing before calling it, e.g. TcpListener::from_std_manually_configured_as_non_blocking
Additional context
It seems that this used to be the way this worked, but was changed propagating a change from downstream.
I would tend to think that it may have been best to not propagate that change directly, and instead do one of the two things above.