feat: optimize logs for server started (#883)

Signed-off-by: Gaius <gaius.qi@gmail.com>
This commit is contained in:
Gaius 2024-12-05 13:42:11 +08:00 committed by GitHub
parent 4b682b9c09
commit 47e38cbe04
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 6 deletions

View File

@ -140,16 +140,21 @@ impl DfdaemonDownloadServer {
.add_service(health_service)
.add_service(self.service.clone())
.serve_with_incoming_shutdown(uds_stream, async move {
// When the grpc server is started, notify the barrier. If the shutdown signal is received
// before barrier is waited successfully, the server will shutdown immediately.
tokio::select! {
// Notify the download grpc server is started.
_ = grpc_server_started_barrier.wait() => {
info!("proxy download server is ready to start");
info!("download server is ready to start");
}
// Wait for shutdown signal.
_ = shutdown.recv() => {
info!("download grpc server stop to wait");
}
}
// Wait for the shutdown signal to shutdown the upload grpc server,
// when server is started.
let _ = shutdown.recv().await;
info!("download grpc server shutting down");
});

View File

@ -141,6 +141,8 @@ impl DfdaemonUploadServer {
.add_service(health_service)
.add_service(self.service.clone())
.serve_with_shutdown(self.addr, async move {
// When the grpc server is started, notify the barrier. If the shutdown signal is received
// before barrier is waited successfully, the server will shutdown immediately.
tokio::select! {
// Notify the upload grpc server is started.
_ = grpc_server_started_barrier.wait() => {
@ -148,11 +150,14 @@ impl DfdaemonUploadServer {
}
// Wait for shutdown signal.
_ = shutdown.recv() => {
info!("download grpc server stop to wait");
info!("upload grpc server stop to wait");
}
}
// Wait for the shutdown signal to shutdown the upload grpc server,
// when server is started.
let _ = shutdown.recv().await;
info!("download grpc server shutting down");
info!("upload grpc server shutting down");
});
// Wait for the upload grpc server to shutdown.

View File

@ -151,6 +151,8 @@ impl Proxy {
pub async fn run(&self, grpc_server_started_barrier: Arc<Barrier>) -> ClientResult<()> {
let mut shutdown = self.shutdown.clone();
// When the grpc server is started, notify the barrier. If the shutdown signal is received
// before barrier is waited successfully, the server will shutdown immediately.
tokio::select! {
// Wait for starting the proxy server
_ = grpc_server_started_barrier.wait() => {
@ -171,9 +173,6 @@ impl Proxy {
info!("proxy server listening on {}", self.addr);
loop {
// Clone the shutdown channel.
let mut shutdown = self.shutdown.clone();
// Wait for a client connection.
tokio::select! {
tcp_accepted = listener.accept() => {