Skip to content

Commit 8eb6fac

Browse files
authored
Merge pull request #42 from omnia-network/refactor/do-not-wait-for-update-call
refactor: do not wait for update call when relaying message to canister
2 parents 1313a57 + 8fa7d2c commit 8eb6fac

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/ic-websocket-gateway/src/client_session.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use futures_util::{
99
use gateway_state::CanisterPrincipal;
1010
use ic_agent::{
1111
agent::{Envelope, EnvelopeContent},
12-
Agent, AgentError,
12+
Agent,
1313
};
1414
use serde::{Deserialize, Serialize};
1515
use serde_cbor::{from_slice, to_vec};
@@ -364,9 +364,7 @@ impl<S: AsyncRead + AsyncWrite + Unpin> ClientSession<S> {
364364
let canister_id = self.canister_id.expect("must be set");
365365

366366
// relay the envelope to the IC
367-
self.relay_envelope_to_canister(serialized_envelope, canister_id)
368-
.await
369-
.map_err(|e| IcWsError::IcWsProtocol(e.to_string()))?;
367+
self.relay_envelope_to_canister(serialized_envelope, canister_id);
370368

371369
// there is no need to relay the response back to the client as the response to a request to the /call endpoint is not certified by the canister
372370
// and therefore could be manufactured by the gateway
@@ -380,15 +378,20 @@ impl<S: AsyncRead + AsyncWrite + Unpin> ClientSession<S> {
380378
}
381379
}
382380

383-
async fn relay_envelope_to_canister(
384-
&self,
385-
serialized_envelope: Vec<u8>,
386-
canister_id: Principal,
387-
) -> Result<(), AgentError> {
388-
self.agent
389-
.update_signed(canister_id, serialized_envelope)
390-
.await?;
391-
Ok(())
381+
fn relay_envelope_to_canister(&self, serialized_envelope: Vec<u8>, canister_id: Principal) {
382+
let agent = self.agent.clone();
383+
tokio::spawn(
384+
async move {
385+
match agent.update_signed(canister_id, serialized_envelope).await {
386+
Ok(_) => (),
387+
Err(e) => {
388+
let err = IcWsError::IcWsProtocol(e.to_string());
389+
error!("Error relaying envelope to canister: {:?}", err)
390+
},
391+
}
392+
}
393+
.in_current_span(),
394+
);
392395
}
393396

394397
async fn handle_open_transition(

0 commit comments

Comments
 (0)