From e326d475f7854e4706d70e4f083b0259e63096b3 Mon Sep 17 00:00:00 2001 From: Taylor Thomas Date: Mon, 7 Mar 2022 14:41:14 -0700 Subject: [PATCH] fix(rpc): Prevents early provider exit when logger is set Previous to this change, if a provider set a logger, it would cause the provider to exit early. This changes the setup to simply log a message if the provider already created a logger rather than exiting early Signed-off-by: Taylor Thomas --- rpc-rs/Cargo.toml | 2 +- rpc-rs/src/provider_main.rs | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/rpc-rs/Cargo.toml b/rpc-rs/Cargo.toml index d6f1ea8..0baddcc 100644 --- a/rpc-rs/Cargo.toml +++ b/rpc-rs/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasmbus-rpc" -version = "0.8.2" +version = "0.8.3" authors = [ "wasmcloud Team" ] license = "Apache-2.0" description = "Runtime library for actors and capability providers" diff --git a/rpc-rs/src/provider_main.rs b/rpc-rs/src/provider_main.rs index 9ca2905..7922206 100644 --- a/rpc-rs/src/provider_main.rs +++ b/rpc-rs/src/provider_main.rs @@ -73,9 +73,15 @@ where use std::str::FromStr as _; // initialize logger - let log_rx = crate::channel_log::init_logger() - .map_err(|_| RpcError::ProviderInit("log already initialized".to_string()))?; - crate::channel_log::init_receiver(log_rx); + match crate::channel_log::init_logger() { + Ok(log_rx) => crate::channel_log::init_receiver(log_rx), + // TODO(thomastaylor312): This is brittle, but the init_logger function is public and this + // is a bug fix. For the next major release, we should create an enum return type + Err(e) if e.contains("logger init error") => { + eprintln!("Logger was already created by provider, skipping receiver initialization"); + } + Err(e) => return Err(e.into()), + } let (shutdown_tx, shutdown_rx) = tokio::sync::oneshot::channel(); eprintln!(