Repository navigation
Use CHM for invertedVisibilityEntities - #536
Conversation
|
Thanks, the CHM change looks right. There are a few more places with the same kind of problem:
|
|
Title might need a few changes but went ahead and resolved the remaining concerns elsewhere that we also didn't cover in our upstream! Let me know if there's any other concerns. |
a33ed99 to
3632a31
Compare
pluginWeakReferences is shared by every region through getPluginWeakReference, and isListed reads unlistedEntities from the joining player's region, so both become thread-safe. setVisibleByDefault resets each player through their own scheduler instead of from the entity's region. Port of PaperMC/Folia#536
|
The |
3632a31 to
3df8bb6
Compare
pluginWeakReferences is shared by every region through getPluginWeakReference, and isListed reads unlistedEntities from the joining player's region, so both become thread-safe. Port of PaperMC/Folia#536
|
Ah thank you for the catch. Didn't take that into consideration here; I was a bit skeptical of that code to begin with! (Going to make a few more edits) |
|
The The |
3df8bb6 to
d3fae3a
Compare
|
I think it'd be worth addressing these issues fully so the topic is closed. Was this a bit more in-line with what you were looking for? |
|
|
Got it. Sorry, still working on this! I'll shoot you an @ when I'm all done. |
d3fae3a to
679ce22
Compare
|
Alrighty, I went ahead and read each suggestion carefully and tested these changes. I couldn't find any new races that any of these adjustments caused. Let me know if everything is now in order, @jpenilla! |
setVisibleByDefault resets every online player from the entity's region, and hidePlayer/showPlayer can target a player on another region, so both read a tracker or a viewer's position and sent chunks from a region that doesn't own them. The tracker updates every nearby player each tick, so skipping those calls loses no pairing. Port of PaperMC/Folia#536
ServerLevel calls CraftPlayer#onEntityRemove for every online player when a non-player entity stops being tracked, on the region that owned the entity, while each player's own region reads and writes the same map through the visibility API and the entity tracker.
pluginWeakReferences is shared by every region through getPluginWeakReference, and isListed reads unlistedEntities from the joining player's region in PlayerList#placeNewPlayer, so both become thread-safe. setVisibleByDefault resets every online player from the entity's region, and hidePlayer/showPlayer can target a player on another region, so both read a tracker or a viewer's position and sent chunks from a region that doesn't own them. The tracker is now only touched from the entity's region, and updatePlayer only for a viewer that region owns; the tracker updates every nearby player each tick, so no pairing is lost. visibleByDefault is volatile because canSee reads it for a player target from other regions.
679ce22 to
4903440
Compare
|
One more related issue that wasn't covered here: |
I did actually catch this a bit further down the line, a bit funny how we both had the same catch! 😂 I'll go ahead and open up another PR addressing some other issues I found and what not soon! Just want to make sure I test my changes a bit more carefully |
setVisibleByDefault resets every online player from the entity's region, and hidePlayer/showPlayer can target a player on another region, so both read a tracker or a viewer's position and sent chunks from a region that doesn't own them. The tracker updates every nearby player each tick, so skipping those calls loses no pairing. Port of PaperMC/Folia#536
Right now every non-player entity that stops being tracked calls
CraftPlayer#onEntityRemoveon every online player (the loop under theTODOinServerLevel), so each player'sinvertedVisibilityEntitiesgets removed from on whatever region that entity was on. At the same time, the player's own region is reading and writing that same map through hide/show and the entity tracker. It's still a plainHashMap, so this can corrupt it, and no plugin has to do anything weird for that to happen; just using the visibility API at all is enough.I went through the other ways to fix this and none of them really hold up:
canSeepath, which runs constantly, on tick threads.A CHM makes the map safe from any region, keeps
canSeelock-free, and doesn't change any behavior. It's the same thingplayersByUUIDandplayersByNamealready do.The second commit covers the rest of what JP found.
pluginWeakReferencesandunlistedEntitiesbecome thread-safe.setVisibleByDefaultresets every online player from the entity's region, andhidePlayer/showPlayercan target a player on another region, so both read a tracker or a viewer's position and sent chunks from a region that doesn't own them. The tracker is now only touched from the entity's region, andupdatePlayeronly for a viewer that region owns. Nothing is lost by skipping the rest, since the tracker updates every nearby player each tick and never pairs a viewer it doesn't own.visibleByDefaultis volatile becausecanSeereads it for player targets from other regions.Dueris fixed the map in Canvas back in January; this is that fix trimmed down.
./gradlew buildpasses and rebuilding the patches leaves no changes.Closes: #448