Skip to content

Commit edec4c3

Browse files
fix(frontend): use dedicated runtime to accept connection (#16838) (#16864)
Co-authored-by: Dylan <chenzl25@mail2.sysu.edu.cn>
1 parent ae7f8af commit edec4c3

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
@@ -256,24 +256,43 @@ pub async fn pg_serve(
256256
let listener = Listener::bind(addr).await?;
257257
tracing::info!(addr, "server started");
258258

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

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

279298
pub async fn handle_connection<S, SM>(

0 commit comments

Comments
 (0)