ref(server): make idle time of a http connection configurable#4248
ref(server): make idle time of a http connection configurable#4248
Conversation
f92738f to
de4b5b1
Compare
de4b5b1 to
eca7427
Compare
| timer: None, | ||
| is_idle: false, |
There was a problem hiding this comment.
Would this work with a single variable deadline: Instant, i.e. let Poll::Ready reset the deadline to a point in the future and Poll::Pending check it?
Is the usage of a timer + boolean an optimization to reduce calls to Instant::now()?
There was a problem hiding this comment.
It does reduce the amount of instants created and I also wanted the timer to only start when you poll a Pending. I initially had a Option<Sleep> implementation, but that re-created the Sleep a bunch which is especially expensive with the Box::pin. In the end that's the approach I liked most.
| /// the [`IdleTimeout`] will abort the operation and return [`std::io::ErrorKind::TimedOut`]. | ||
| pub struct IdleTimeout<T> { | ||
| inner: T, | ||
| timeout: Option<Duration>, |
There was a problem hiding this comment.
Not sure if this would make typing annoying, but it would be cool if timeout was non-optional here. So if there's no timeout set in the config, don't use IdleTimeout.
There was a problem hiding this comment.
That works if we instead use Box<dyn AsyncRead + AsyncWrite + Unpin> as the concrete type returned from the Acceptor or introduce an Either<IdleTimeout<TcpStream>, TcpStream> type. I can do that in a follow-up.
With the idle time configurable we can prevent a pile up of open connections which never see any activity.
See also on the hyper issue tracker: