Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
closes #6826
We have circular depedencies between PeerManager and Client, which we
break via
dyn PeerManagerAdapter
. As this is a real cycle, we close itat runtime by calling
set_recipient
. But today nothing prevents clientfrom sending message to network before that, and indeed that happens if
we are unlucky with timing.
This commit fixes the issue by making
PeerManagerAdapter
APIs blockuntil the loop is closed.
After finishing the implementation, I realized that this might not be the ideal solution. It seems that actix has the API (Actor::create) for tying such loop nicely, where you can get actor's address before creating the actor. We use it, for example, here:
nearcore/integration-tests/src/tests/network/runner.rs
Lines 64 to 70 in d18f345
So, in theory, we can just
impl PeerManagerAdapter for Recipient<PeerManagerMessageRequest>
and then rewrite all call-sites to usecreate
and friends.Upon closer examination, it seems that that is possible, but not trivial, as create API is not orthogonal enough.
Actor::start_in_arbiter
andActor::mock
, which don't have create-like alternatives. We can open-code them, but that's adding more to the framework::create
itself can't return something else, so that means we'd have to use.unwrap
sSo I think it's better to maybe do just what this PR is doing and just fix the current code.
Test Plan
Verify that, after applying the following "unfortunate timing" diff
The following test
fails on master and passes with this PR applied