-
Notifications
You must be signed in to change notification settings - Fork 313
[Users of NetworkPeer + NetworkPeer] Beyond NetworkPeer refactoring - separate Dispose from Disconnect to avoid cyclic calls #1090
Comments
we would maybe want then to introduce OnDisconnect event in NetworkPeer so that those components owning the peer can get notified when this happens (i.e. completely different behavior calls disconnect on their peer) and so they can initiate disposal, but either they would manage themselves that or we would call this OnDisconnect in a non-synchronized fashion, so that we allow disposals from those |
Perhaps we should first refactor that before we go down the odd code pattern in #1079 |
refactoring of NP is taking care of NP, there is just two things to do and the refactor of NP is finished #1079 does not add anything new to NP, those cyclic things were there from beginning, we are just making things simpler and simpler but refactoring of NP has its limits this one touches larger code base, so when NP can't be pushed further, we need to refactor other stuff, which then will allow us to further improve NP stuff it shouldn't be done in different order because those async events are kind of requirement for this |
I think we can avoid cyclic calls without removing the ability to call Dispose from the callbacks. So what we can do is that:
What's the point of notifying peers about a new state when this state is already outdated? Fixing this issue that way will make it a small fix so we won't have to redesign the whole thing |
I don't think that would be safe to do, I can imagine scenarios where component relies on something being that when the peer is switched to certain state and if you just about the execution it won't happen. So to me it seems like such a counterintuitive feature of the callback could lead to more problems than it would solve. And also because the behaviours are not very well designed, I would rather see refactoring that would clean it up |
I don't think we have behaviors that rely on a certain sequence of states being signaled in order to work correctly.
Ok, I don't mind going with the "big redesign" approach. I'll think on the best way of approaching that and post new design suggestion here. |
I think that is the problem, no one knows. And possibly even bigger problem is that such hidden feature could turn against you in the future. The refactoring here would not be that much extreme, the number of behaviours we need to attach is reasonable. We only need extreme amount of testing one this is done and we should be fine. |
Suggested changes: Step 1NetworkPeerBehavior:
Benefits:
Step 2NetworkPeerBehavior:
NetworkPeer:
NetworkPeerBehavior : This will allow the behaviors avoid copy-paste calling of 'AttachedPeer.StateChanged.Register(this.OnStateChangedAsync);' on attach. Those changes will prevent cyclic calls by design. |
I kind of disagree the full step one, this step is unnecessary to fix the issue, it is like completely different thing that is unrelated. Moreover it is already implemented in different class, see network peer listener |
I also disagree with this one, we should disconnect separately because it is exactly this that is causing the mess at this moment As for other suggestions, I will need to look into the code to be able to comment on those |
With those change in place (less states and single DisconnectAndDispose) there won't be place for mess that is currently going on. When peer is being disposed we will first wait until all behaviors are disposed and after that we start our own disposure. I'd agree with you if we would be able to do Disconnect and then Connect again. Without that ability Disconnect is 'dispose, but not completely'. |
peer listener implements pull mechanic so in order to use it we would need to implement a loop that would continuously ask for a specific payload. And if we need 2 different payloads we need 2 loops or implement WhenAny logic. What I want to do is to implement a push mechanic which will make payload processing extremely easy on the user side: create a private method that accepts the payload and register this method on the initialization- that's it.
It is unrelated to the cyclic calls problem but it is related to the refactoring of the behaviors. As you said:
|
I would like to see behaviours refactored, but not as a part of this issue. Let's focus here on removing the cycles and let's keep it minimal. I will explain on Skype why I don't think that the suggested mechanism of registration is good here |
Currently various behaviors call disconnect/dispose on network peer and this leads to cyclic calls like
state changed -> on state changed callback -> dispose peer -> disconnect peer ->state changed to offline -> on state changed callback -> dispose peer
to prevent those, we need to do following steps:
NetworkPeerConnection.Disconnect
)kind of a big task, which won't be included in NetworkPeer refactoring series
once this is done, we can relax (remove functionality) AsyncQueue and maybe even AsyncExecutionEvent, which are now coded in a way that this cyclic calling is allowed
then we can very much refactor NetworkPeer's
Disconnect
and NetworkPeerConnection'sShutdown
, andDispose
, those could be much much simpler after this is no longer neededThe text was updated successfully, but these errors were encountered: