TcpStream::ready() / readable() / writable() returns Result, but the Err are not documented. #5552
-
Hi, TLDRThe errors that From searching into the source code it seems pretty unrecoverable and caused by having the Tokio runtime shutting down. Can someone confirms ? (By the way, other methods (such as into_std) are neither explicitly documented about their errors. I understand that Tokio is a complex cross platform framework that takes care of a lot of low level details and that it is very hard to expose all the errors in a clear manner, and some other errors are opaque too. I still think that in the public API, if a function returns a ContextI am trying to build a complex system, and it has to be super robust, which means good error handling. I am using a Tokio My issue is that I don't understant when will this method return an Some researchUnderneath, it's the more general method The error is not documented and I have no idea what it would mean, and so I don't know how to handle it (beside panic in my project). I dived into the code: pub async fn ready(&self, interest: Interest) -> io::Result<Ready> {
let event = self.io.registration().readiness(interest).await?;
Ok(event.ready)
} Following impl Registration {
pub(crate) async fn readiness(&self, interest: Interest) -> io::Result<ReadyEvent> {
let ev = self.shared.readiness(interest).await;
if ev.is_shutdown {
return Err(gone())
}
Ok(ev)
}
... Ok, so here I can see that there is a boolean flag Following fn gone() -> io::Error {
io::Error::new(
io::ErrorKind::Other,
crate::util::error::RUNTIME_SHUTTING_DOWN_ERROR,
)
} Ok, now I see the only possible error is an Let's see what is the /// Error string explaining that the Tokio context is shutting down and cannot drive timers.
pub(crate) const RUNTIME_SHUTTING_DOWN_ERROR: &str =
"A Tokio 1.x context was found, but it is being shutdown."; My conclusionOk, it seems pretty clear now that if Did I get that right ? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
We cannot exhaustively list all reasons it might fail, but all errors it might return are unrecoverable. |
Beta Was this translation helpful? Give feedback.
We cannot exhaustively list all reasons it might fail, but all errors it might return are unrecoverable.