Skip to content

Commit f87d11d

Browse files
committed
fix: remove unused try buffer
1 parent d57653c commit f87d11d

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

src/api/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use anyhow::Result;
22
use futures_util::future::OptionFuture;
3-
use futures_util::FutureExt;
3+
use futures_util::{FutureExt, TryStreamExt};
44
use metrics::{metrics, metrics_wrapper};
55
use sqlx::PgPool;
66
use tokio::net::TcpListener;
@@ -28,12 +28,12 @@ pub async fn new(
2828
let routes = routes::routes(pool.clone());
2929

3030
let http = http
31-
.map(move |http| proxy::wrap(http, http_proxy))
31+
.map(move |http| proxy::wrap(http, http_proxy).try_buffer_unordered(100))
3232
.map(|http| warp::serve(routes.clone()).serve_incoming(http))
3333
.map(tokio::spawn);
3434

3535
let prom = prom
36-
.map(move |prom| proxy::wrap(prom, prom_proxy))
36+
.map(move |prom| proxy::wrap(prom, prom_proxy).try_buffer_unordered(100))
3737
.map(|prom| warp::serve(metrics()).serve_incoming(prom))
3838
.map(tokio::spawn);
3939

src/api/proxy.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::config::ProxyProtocol;
1919
pub(super) fn wrap(
2020
listener: TcpListener,
2121
proxy: ProxyProtocol,
22-
) -> impl Stream<Item = IoResult<ProxyStream>> + Send {
22+
) -> impl Stream<Item = IoResult<impl Future<Output = IoResult<ProxyStream>>>> + Send {
2323
TcpListenerStream::new(listener)
2424
.map_ok(move |stream| stream.source(proxy))
2525
.map_ok(|mut conn| {
@@ -40,7 +40,6 @@ pub(super) fn wrap(
4040
}
4141
.instrument(span)
4242
})
43-
.try_buffer_unordered(100)
4443
}
4544

4645
pub(super) trait ToProxyStream {

src/api/tls.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use anyhow::{anyhow, Error, Result};
22
use futures_util::stream::{repeat, Stream};
3-
use futures_util::{StreamExt, TryStreamExt};
3+
use futures_util::{StreamExt, TryStreamExt, TryFutureExt};
44
use parking_lot::RwLock;
55
use rustls::internal::pemfile::{certs, pkcs8_private_keys};
66
use rustls::{NoClientAuth, ServerConfig};
77
use sqlx::PgPool;
8+
use std::future::Future;
89
use std::sync::Arc;
910
use tokio::io::{AsyncRead, AsyncWrite, Result as IoResult};
1011
use tokio_rustls::TlsAcceptor;
@@ -14,10 +15,13 @@ use super::proxy::ProxyStream;
1415
use crate::cert::{Cert, CertFacade};
1516
use crate::util::to_u64;
1617

17-
pub(super) fn wrap(
18-
listener: impl Stream<Item = IoResult<ProxyStream>> + Send,
18+
pub(super) fn wrap<L, I>(
19+
listener: L,
1920
pool: PgPool,
2021
) -> impl Stream<Item = Result<impl AsyncRead + AsyncWrite + Send + Unpin + 'static, Error>> + Send
22+
where
23+
L: Stream<Item = IoResult<I>> + Send,
24+
I: Future<Output = IoResult<ProxyStream>> + Send,
2125
{
2226
let acceptor = Acceptor::new(pool);
2327

@@ -26,13 +30,12 @@ pub(super) fn wrap(
2630
.zip(repeat(acceptor))
2731
.map(|(conn, acceptor)| conn.map(|c| (c, acceptor)))
2832
.map_ok(|(conn, acceptor)| async move {
29-
let tls = acceptor.load_cert().await?;
33+
let (conn, tls) = tokio::try_join!(conn.err_into(), acceptor.load_cert())?;
3034
Ok(tls.accept(conn).await?)
3135
})
3236
.try_buffer_unordered(100)
3337
.inspect_err(|err| error!("Stream error: {:?}", err))
3438
.filter(|stream| futures_util::future::ready(stream.is_ok()))
35-
.into_stream()
3639
}
3740

3841
struct Acceptor {

0 commit comments

Comments
 (0)