Skip to content

Commit

Permalink
Fix creation of gRPC sessions (#949)
Browse files Browse the repository at this point in the history
Check outgoing channels
  • Loading branch information
iliailia authored Jan 16, 2025
1 parent 2cae51a commit d27b53e
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion iris-mpc-cpu/src/network/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ impl OutgoingStreams {
))
.map(|s| s.value().clone())
}

fn contains_session(&self, session_id: SessionId) -> bool {
self.streams.iter().any(|v| v.key().0 == session_id)
}
}

#[derive(Default, Clone)]
Expand Down Expand Up @@ -139,7 +143,7 @@ impl GrpcNetworking {
}

pub async fn create_session(&self, session_id: SessionId) -> eyre::Result<()> {
if self.message_queues.contains_key(&session_id) {
if self.outgoing_streams.contains_session(session_id) {
return Err(eyre!(
"Player {:?} has already created session {session_id:?}",
self.party_id
Expand Down Expand Up @@ -403,6 +407,7 @@ mod tests {

// Each party sending and receiving messages to each other
{
let players = players.clone();
jobs.spawn(async move {
let session_id = SessionId::from(1);

Expand Down Expand Up @@ -455,6 +460,18 @@ mod tests {
});
}

// Parties create a session consecutively
{
let players = players.clone();
jobs.spawn(async move {
let session_id = SessionId::from(2);

for player in players.iter() {
player.create_session(session_id).await.unwrap();
}
});
}

jobs.join_all().await;

Ok(())
Expand Down

0 comments on commit d27b53e

Please sign in to comment.