Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear peers on disconnect #168

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

AndrewMeadows
Copy link

This PR fixes bug HIFI-847 in the JS API.
https://highfidelity.atlassian.net/browse/HIFI-847

This work is a theoretical fix: I haven't been able to test it yet.

}
// TODO: remove the entry from the peer state cache -- is this OK?
//delete this._mixerPeerKeyToStateCacheDict[mixerPeerKey];
delete this._mixerPeerKeyToStateCacheDict[key];
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While looking over the code I noticed this for loop was performing double map lookups in _mixerPeerKeyToStateCacheDict in the common case and triple lookups in the uncommon. This offends my sensibilities for high performance code and so I was compelled to fix it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, also notice that I did uncomment the code for the old TODO. Yes, it is a good idea to actually purge old peer data from the cache when it gets deleted.

@@ -699,6 +699,7 @@ export class HiFiMixerSession {
await close(this._raviSignalingConnection, "Signaling Connection", RaviSignalingStates.CLOSED);
await close(this._raviSession, "Session", RaviSessionStates.CLOSED);

this._clearPeerData();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the real fix for HIFI-847: clear the peer cache on disconnect.

allDeletedUserData.push(deletedUserData);
}
this.onUsersDisconnected(allDeletedUserData);
}
this._mixerPeerKeyToStateCacheDict = {};
}
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: we aren't just clearing the peer cache here. If onUserDisconnect callback exists we also assemble allDeletedUserData and feed it to onUserDisconnect. This tells the Application to remove any stale peer data it happens to be using.

this.onUsersDisconnected(allDeletedUserData);
}
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've moved the handling of deleted_visit_ids down below the handling of peers. It is theoretically possible for a change to exist in peers for someone who was also deleted in the same frame, and when a change is not found in the map the peer is added to it. By handling the deletions last we can avoid re-adding the changed user after deletion.

if (peerData.providedUserID) {
deletedUserData.providedUserID = peerData.providedUserID;
}
delete this._mixerPeerKeyToStateCacheDict[key];
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I'm correctly deleting the peer from the map on delete. Previously this operation was commented out with a TODO comment about it (see the above removed block).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants