Skip to content

Commit

Permalink
Merge branch 'tim/fix-serialize' into 'master'
Browse files Browse the repository at this point in the history
fix(consensus-manager): Don't hold lock on artifact pool during response serialization in rpc endpoint

If serialization is done within `map` the read lock is not released for the duration of the serialization which adds unnecessary lock contention. 

See merge request dfinity-lab/public/ic!16626
  • Loading branch information
tthebst committed Dec 13, 2023
2 parents bc75916 + 951a8b1 commit c36fa97
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions rs/p2p/consensus_manager/src/receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,14 @@ async fn rpc_handler<Artifact: ArtifactKind>(
let jh = tokio::task::spawn_blocking(move || {
let id: Artifact::Id =
Artifact::PbId::proxy_decode(&payload).map_err(|_| StatusCode::BAD_REQUEST)?;
Ok::<_, StatusCode>(
pool.read()
.unwrap()
.get_validated_by_identifier(&id)
.map(|msg| Bytes::from(Artifact::PbMessage::proxy_encode(msg))),
)
let artifact = pool
.read()
.unwrap()
.get_validated_by_identifier(&id)
.ok_or(StatusCode::NO_CONTENT)?;
Ok::<_, StatusCode>(Bytes::from(Artifact::PbMessage::proxy_encode(artifact)))
});
let bytes = jh
.await
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)??
.ok_or(StatusCode::NO_CONTENT)?;
let bytes = jh.await.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)??;

Ok(bytes)
}
Expand Down

0 comments on commit c36fa97

Please sign in to comment.