Skip to content

Commit

Permalink
feat: gracefully shutdown grpc server
Browse files Browse the repository at this point in the history
  • Loading branch information
Cifko committed Jan 9, 2023
1 parent b3380c7 commit 947faf6
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions applications/tari_console_wallet/src/wallet_modes.rs
Expand Up @@ -271,7 +271,12 @@ pub fn tui_mode(
if config.grpc_enabled {
if let Some(address) = config.grpc_address.clone() {
let grpc = WalletGrpcServer::new(wallet.clone());
handle.spawn(run_grpc(grpc, address, config.grpc_authentication.clone()));
handle.spawn(run_grpc(
grpc,
address,
config.grpc_authentication.clone(),
wallet.clone(),
));
}
}

Expand Down Expand Up @@ -369,10 +374,10 @@ pub fn recovery_mode(
pub fn grpc_mode(handle: Handle, config: &WalletConfig, wallet: WalletSqlite) -> Result<(), ExitError> {
info!(target: LOG_TARGET, "Starting grpc server");
if let Some(address) = config.grpc_address.as_ref().filter(|_| config.grpc_enabled).cloned() {
let grpc = WalletGrpcServer::new(wallet);
let grpc = WalletGrpcServer::new(wallet.clone());
let auth = config.grpc_authentication.clone();
handle
.block_on(run_grpc(grpc, address, auth))
.block_on(run_grpc(grpc, address, auth, wallet))
.map_err(|e| ExitError::new(ExitCode::GrpcError, e))?;
} else {
println!("GRPC server is disabled");
Expand All @@ -385,6 +390,7 @@ async fn run_grpc(
grpc: WalletGrpcServer,
grpc_listener_addr: Multiaddr,
auth_config: GrpcAuthentication,
wallet: WalletSqlite,
) -> Result<(), String> {
// Do not remove this println!
const CUCUMBER_TEST_MARKER_A: &str = "Tari Console Wallet running... (gRPC mode started)";
Expand All @@ -397,7 +403,7 @@ async fn run_grpc(

Server::builder()
.add_service(service)
.serve(address)
.serve_with_shutdown(address, wallet.wait_until_shutdown())
.await
.map_err(|e| format!("GRPC server returned error:{}", e))?;

Expand Down

0 comments on commit 947faf6

Please sign in to comment.