set SO_LINGER (0) for misbehav clients before close()

This commit is contained in:
zonyitoo
2022-05-15 11:49:01 +08:00
parent 03651f3968
commit ce08be7a31
2 changed files with 11 additions and 0 deletions
@@ -35,6 +35,11 @@ impl<S> MonProxyStream<S> {
pub fn get_mut(&mut self) -> &mut S {
&mut self.stream
}
#[inline]
pub fn into_inner(self) -> S {
self.stream
}
}
impl<S> AsyncRead for MonProxyStream<S>
@@ -132,6 +132,12 @@ impl TcpServerClient {
#[cfg(feature = "aead-cipher-2022")]
if self.method.is_aead_2022() {
// Set SO_LINGER(0) for misbehave clients, which will eventually receive RST. (ECONNRESET)
// This will also prevent the socket entering TIME_WAIT state.
let stream = self.stream.into_inner().into_inner();
let _ = stream.set_linger(Some(Duration::ZERO));
return Ok(());
}