From 7aa5999b3c3363396994eb3a71929f3561fd50ee Mon Sep 17 00:00:00 2001 From: Devashish Date: Tue, 25 Aug 2020 01:55:54 +0000 Subject: [PATCH] Problem: ra-sp-server crashes sometimes Solution: Added 6 retries for `AesmClient` at an interval of 2 secs each. Fixes #2175. --- .../enclave-ra/ra-sp-server/src/context.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/chain-tx-enclave-next/enclave-ra/ra-sp-server/src/context.rs b/chain-tx-enclave-next/enclave-ra/ra-sp-server/src/context.rs index 80e13f8e5..f45bf8243 100644 --- a/chain-tx-enclave-next/enclave-ra/ra-sp-server/src/context.rs +++ b/chain-tx-enclave-next/enclave-ra/ra-sp-server/src/context.rs @@ -23,9 +23,7 @@ impl SpRaContext { /// Creates a new SP remote attestation context pub fn new(config: SpRaConfig) -> Result { let aesm_client = AesmClient::new(); - let quote_info = aesm_client - .init_quote() - .map_err(SpRaContextError::AesmError)?; + let quote_info = get_quote_info(&aesm_client)?; let quote_type = config.quote_type; let ias_client = IasClient::new( @@ -95,6 +93,19 @@ impl SpRaContext { } } +fn get_quote_info(aesm_client: &AesmClient) -> Result { + for _ in 0..5 { + match aesm_client.init_quote() { + Ok(quote_info) => return Ok(quote_info), + Err(_) => std::thread::sleep(std::time::Duration::from_secs(2)), + } + } + + aesm_client + .init_quote() + .map_err(SpRaContextError::AesmError) +} + fn parse_quote_type(quote_type: &str) -> Result { match quote_type { "Linkable" => Ok(QuoteType::Linkable),