-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: