Repository navigation
fix: NetworkList changes pending during client synchronization are applied twice - #4200
Open
quantum-shubham wants to merge 1 commit into
Conversation
…plied twice Override WriteFieldSynchronization in NetworkList<T> so a client synchronized while local changes are still pending receives the list as of the last sent delta, mirroring NetworkVariable<T>. The pending events are then applied exactly once with the next delta. Fixes Unity-Technologies#4179
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
TITLE:
fix: NetworkList changes pending during client synchronization are applied twice
BODY:
Purpose of this PR
Fixes #4179
If a client is synchronized while a
NetworkList<T>still has unsent changes, the synchronization snapshot already contains those changes. On the next tick the same events are sent to the new observer again. Add, Insert, Remove, RemoveAt and Set are not idempotent, so the late-joining client ends up with duplicate entries, and later index-based events land on the wrong elements. #3081 fixed this forNetworkVariable<T>throughWriteFieldSynchronization, butNetworkList<T>never overrode it.NetworkList<T>now overridesWriteFieldSynchronization, mirroringNetworkVariable<T>. While local changes are pending, it writes the list as it was before the first of them. The pending events then bring the client up to date exactly once with the next delta.The copy is taken just before the first local change after a delta is sent, and the flag is cleared in
ResetDirty. It is not refreshed inResetDirty, because there it could go stale on instances whereResetDirtydoesn't run, such as a non-writer that later becomes owner. Paths without locally pending events behave exactly as before: server forwarding of owner-write deltas,NetworkShow(already flushed byForceSendIfDirtyOnNetworkShow), and spawn.Tradeoff: each
NetworkList<T>keeps one extra native buffer, and the writer does one copy per dirty period.Jira ticket
N/A (GitHub issue #4179)
Changelog
NetworkList<T>still had unsent changes applied those changes twice, resulting in duplicate entries and index-based events landing on the wrong elements on that client.Documentation
Testing & QA (How your changes can be verified during release Playtest)
Functional Testing
Manual testing :
Manual testing doneAutomated tests:
Covered by existing automated testsCovered by new automated testsNew
NetworkListTests.LateJoinWithPendingChanges(Host / DAHost / Server). It holds deltas back withMinSecondsBetweenUpdates, applies Add/Insert/RemoveAt/Set/Remove, late-joins a client, checks the changes are still pending, releases them, and verifies every client matches.Expected: 5, Have: 6on the late-joined client).testproject) passed 1044/1044 across the related suites: NetworkVariable*, NetworkList*, NetworkShowHide, NetworkObjectSynchronization, NetworkObjectOwnership, OwnerModified and the permission/hidden variable tests.Does the change require QA team to:
Review automated tests?Execute manual tests?Provide feedback about the PR?Up-port
The same code exists on
develop-3.x.x. I can open the up-port PR once this one is reviewed.Backports
Not needed.