Skip to content

Commit fb88b6d

Browse files
authored
fix(frontend): use dedicated runtime to accept connection (#16838)
1 parent 3d58cc7 commit fb88b6d

File tree

1 file changed

+34
-15
lines changed

1 file changed

+34
-15
lines changed

src/utils/pgwire/src/pg_server.rs

+34-15
Original file line numberDiff line numberDiff line change
@@ -255,24 +255,43 @@ pub async fn pg_serve(
255255
let listener = Listener::bind(addr).await?;
256256
tracing::info!(addr, "server started");
257257

258-
loop {
259-
let conn_ret = listener.accept().await;
260-
match conn_ret {
261-
Ok((stream, peer_addr)) => {
262-
tracing::info!(%peer_addr, "accept connection");
263-
tokio::spawn(handle_connection(
264-
stream,
265-
session_mgr.clone(),
266-
tls_config.clone(),
267-
Arc::new(peer_addr),
268-
));
269-
}
258+
let acceptor_runtime = {
259+
let mut builder = tokio::runtime::Builder::new_multi_thread();
260+
builder.worker_threads(1);
261+
builder
262+
.thread_name("rw-acceptor")
263+
.enable_all()
264+
.build()
265+
.unwrap()
266+
};
270267

271-
Err(e) => {
272-
tracing::error!(error = %e.as_report(), "failed to accept connection",);
268+
#[cfg(not(madsim))]
269+
let worker_runtime = tokio::runtime::Handle::current();
270+
#[cfg(madsim)]
271+
let worker_runtime = tokio::runtime::Builder::new_multi_thread().build().unwrap();
272+
273+
let f = async move {
274+
loop {
275+
let conn_ret = listener.accept().await;
276+
match conn_ret {
277+
Ok((stream, peer_addr)) => {
278+
tracing::info!(%peer_addr, "accept connection");
279+
worker_runtime.spawn(handle_connection(
280+
stream,
281+
session_mgr.clone(),
282+
tls_config.clone(),
283+
Arc::new(peer_addr),
284+
));
285+
}
286+
287+
Err(e) => {
288+
tracing::error!(error = %e.as_report(), "failed to accept connection",);
289+
}
273290
}
274291
}
275-
}
292+
};
293+
acceptor_runtime.spawn(f).await?;
294+
Ok(())
276295
}
277296

278297
pub async fn handle_connection<S, SM>(

0 commit comments

Comments
 (0)