add timeout for wss try_accept

public server should show stats

use default values for flags

bump version to 2.0.0
This commit is contained in:
sijie.sun
2024-09-27 21:42:11 +08:00
committed by Sijie.Sun
parent ff5ee8a05e
commit d0a3a40a0f
9 changed files with 65 additions and 17 deletions

View File

@@ -1,9 +1,12 @@
use std::{net::SocketAddr, sync::Arc};
use std::{net::SocketAddr, sync::Arc, time::Duration};
use anyhow::Context;
use bytes::BytesMut;
use futures::{stream::FuturesUnordered, SinkExt, StreamExt};
use tokio::net::{TcpListener, TcpSocket, TcpStream};
use tokio::{
net::{TcpListener, TcpSocket, TcpStream},
time::timeout,
};
use tokio_rustls::TlsAcceptor;
use tokio_websockets::{ClientBuilder, Limits, MaybeTlsStream, Message};
use zerocopy::AsBytes;
@@ -141,9 +144,9 @@ impl TunnelListener for WSTunnelListener {
// only fail on tcp accept error
let (stream, _) = listener.accept().await?;
stream.set_nodelay(true).unwrap();
match self.try_accept(stream).await {
Ok(tunnel) => return Ok(tunnel),
Err(e) => {
match timeout(Duration::from_secs(3), self.try_accept(stream)).await {
Ok(Ok(tunnel)) => return Ok(tunnel),
e => {
tracing::error!(?e, ?self, "Failed to accept ws/wss tunnel");
continue;
}