From 3ab0a09ee817ce68bf5fa1d38327354cd7088a1b Mon Sep 17 00:00:00 2001 From: etorreborre Date: Mon, 2 Oct 2023 15:30:15 +0200 Subject: [PATCH] refactor(rust): delay the unwrapping of the response of a secure request and stop the secure channel before unwrapping --- .../ockam_identity/src/secure_channels/secure_client.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/implementations/rust/ockam/ockam_identity/src/secure_channels/secure_client.rs b/implementations/rust/ockam/ockam_identity/src/secure_channels/secure_client.rs index 28ce4d3da3d..24d33418043 100644 --- a/implementations/rust/ockam/ockam_identity/src/secure_channels/secure_client.rs +++ b/implementations/rust/ockam/ockam_identity/src/secure_channels/secure_client.rs @@ -148,11 +148,13 @@ impl SecureClient { let sc = self.create_secure_channel(ctx).await?; let route = route![sc.clone(), api_service]; let client = Client::new(&route, Some(timeout)); - let response = client.request(ctx, req).await?; + let response = client.request(ctx, req).await; self.secure_channels .stop_secure_channel(ctx, sc.encryptor_address()) .await?; - Ok(response) + // we delay the unwrapping of the response to make sure that the secure channel is + // properly stopped first + Ok(response?) } /// Create a secure channel to the node