Skip to content

Commit 5556c54

Browse files
committed
chore: minor update
Signed-off-by: shuiyisong <[email protected]>
1 parent a0d39f3 commit 5556c54

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

src/common/grpc/src/channel_manager.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use tonic::transport::{
3131
use tower::Service;
3232

3333
use crate::error::{CreateChannelSnafu, InvalidConfigFilePathSnafu, Result};
34-
use crate::reloadable_tls::{ReloadableTlsConfig, TlsConfigLoader};
34+
use crate::reloadable_tls::{ReloadableTlsConfig, TlsConfigLoader, maybe_watch_tls_config};
3535

3636
const RECYCLE_CHANNEL_INTERVAL_SECS: u64 = 60;
3737
pub const DEFAULT_GRPC_REQUEST_TIMEOUT_SECS: u64 = 10;
@@ -340,13 +340,11 @@ pub fn load_client_tls_config(
340340

341341
pub fn maybe_watch_client_tls_config(
342342
client_tls_config: Arc<ReloadableClientTlsConfig>,
343-
channel_manager: &ChannelManager,
343+
channel_manager: ChannelManager,
344344
) -> Result<()> {
345-
let channel_manager_for_watcher = channel_manager.clone();
346-
347-
crate::reloadable_tls::maybe_watch_tls_config(client_tls_config, move || {
345+
maybe_watch_tls_config(client_tls_config, move || {
348346
// Clear all existing channels to force reconnection with new certificates
349-
channel_manager_for_watcher.clear_all_channels();
347+
channel_manager.clear_all_channels();
350348
info!("Cleared all existing channels to use new TLS certificates.");
351349
})
352350
}

src/common/grpc/src/reloadable_tls.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
use std::path::Path;
16+
use std::result::Result as StdResult;
1617
use std::sync::atomic::{AtomicUsize, Ordering};
1718
use std::sync::mpsc::channel;
1819
use std::sync::{Arc, RwLock};
@@ -28,7 +29,7 @@ pub trait TlsConfigLoader<T> {
2829
type Error;
2930

3031
/// Load the TLS configuration
31-
fn load(&self) -> std::result::Result<Option<T>, Self::Error>;
32+
fn load(&self) -> StdResult<Option<T>, Self::Error>;
3233

3334
/// Get paths to certificate files for watching
3435
fn watch_paths(&self) -> Vec<&Path>;
@@ -57,7 +58,7 @@ where
5758
O: TlsConfigLoader<T>,
5859
{
5960
/// Create config by loading configuration from the option type
60-
pub fn try_new(tls_option: O) -> std::result::Result<Self, O::Error> {
61+
pub fn try_new(tls_option: O) -> StdResult<Self, O::Error> {
6162
let config = tls_option.load()?;
6263
Ok(Self {
6364
tls_option,
@@ -67,7 +68,7 @@ where
6768
}
6869

6970
/// Reread certificates and keys from file system.
70-
pub fn reload(&self) -> std::result::Result<(), O::Error> {
71+
pub fn reload(&self) -> StdResult<(), O::Error> {
7172
let config = self.tls_option.load()?;
7273
*self.config.write().unwrap() = config;
7374
self.version.fetch_add(1, Ordering::Relaxed);

src/common/grpc/tests/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ async fn test_reloadable_client_tls_config() {
108108
let config = ChannelConfig::new();
109109
let manager = ChannelManager::with_config(config, Some(reloadable_config.clone()));
110110

111-
maybe_watch_client_tls_config(reloadable_config.clone(), &manager)
111+
maybe_watch_client_tls_config(reloadable_config.clone(), manager.clone())
112112
.expect("failed to watch client config");
113113

114114
assert_eq!(0, reloadable_config.get_version());

0 commit comments

Comments
 (0)