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

Fix packet duplicating at some points #8566

Merged
merged 1 commit into from
Nov 27, 2022

Conversation

sandtechnology
Copy link
Contributor

@sandtechnology sandtechnology commented Nov 14, 2022

Overview:
Due to the weakly consistent of ConcurrentLinkedQueue iterator, at some points, packet will be resent twice times or more, causing some weird behaviors (e.g. kicked for illegal movement since the same ClientboundPlayerPositionPacket was sent two times). This changes for the patch add a flag for marking if the packet was consumed to prevent such issue and ensure consistently of the packet queue.

Related issue:
PotatoCraft-Studio/QuickShop-Reremake#255
QuickShop-Community/QuickShop-Hikari#517

Related logs (By adding debug log):
https://pastebin.com/eqfsz2kn

Paper build for testing (Updated):
https://mega.nz/file/BwA3HC7I#qZgM8b93X0NKiidE3prUFZkg7aqdetgS3jiLgu8r-K4

Additional Information:
Spigot does not have this issue because the original one is using poll method, and paper is using iterator for anti-xray feature.

Download the paperclip jar for this pull request: paper-8566.zip

@sandtechnology sandtechnology requested a review from a team as a code owner November 14, 2022 12:13
@Ghost-chu
Copy link

Ghost-chu commented Nov 14, 2022

I can confirm this bug cause user kicked by reason Invalid move player packet received.

Everything works properly with patched Paper build.

also may be related to
#8222

@electronicboy
Copy link
Member

Changes fixing issues induced by patches should go into the original patch, rather than as an extra patch down the line;

I'm also not fond of this fix as it's not really fixing the underlying issue, really, that loop needs changing back into a peek/poll loop which will properly manage the queue rather than trying to mangle it with state flags

@sandtechnology
Copy link
Contributor Author

sandtechnology commented Nov 15, 2022

Changes fixing issues induced by patches should go into the original patch, rather than as an extra patch down the line;

I'm also not fond of this fix as it's not really fixing the underlying issue, really, that loop needs changing back into a peek/poll loop which will properly manage the queue rather than trying to mangle it with state flags

Thanks for the suggestion! I will made this change to previous patches and change it back to poll loop, and seems this change conflicted with couples patches, it will need some time to done.

@Spottedleaf
Copy link
Member

The poll loop will not fix this either. There's no way to use CLQ with some kind of conditional poll logic, which is why the iterator was used. However, the iterator doesn't actually fix the issue as it does not indicate to the caller whether the node was actually removed by the remove() call or was already removed.

You can fix this issue by using an AtomicBoolean on the PacketHolder class and use getAndSet(true) to atomically mark a packet as sent and check if it was already sent.

@sandtechnology
Copy link
Contributor Author

sandtechnology commented Nov 15, 2022

Originally I want to use an variable with mutex to save the unready packet and restore to poll loop, but I found it's bad for readability and maintainability, because it needs change all packet queue related stuff to made it behave normally, which brings more code changes and more complex than the original one.

So I choose just merge current changes to original patch and apply the suggestion from Spottedleaf (Thanks for it!), change the variable type to AtomicBoolean, also think more about muti-threading - let it become the isConsumed flag and use compareAndSet to ensure don't be consumed twice times, it should be looks good enough now.

Test jar will be updated later, it needs sometime to build.

@sandtechnology
Copy link
Contributor Author

Emmmm, look like the patch file is broken for incorrectly conflict solving, will fix it later

@sandtechnology sandtechnology force-pushed the master branch 2 times, most recently from c999e15 to 69c0108 Compare November 15, 2022 18:09
@sandtechnology
Copy link
Contributor Author

Tested with the newest changes and seems still work for me, now this PR is ready for review again, paper build also was updated for testing.

@sandtechnology
Copy link
Contributor Author

It has been 9 days, When this PR will be merged? Does it require me to do any extra things?

@xism4
Copy link

xism4 commented Nov 24, 2022

It has been 9 days, When this PR will be merged? Does it require me to do any extra things?

They aproved it, probably they're just waiting for some other reviewer?

@tillhfm
Copy link

tillhfm commented Nov 24, 2022

I had a short convo with a paper mod on Sunday about this issue because I need it to be merged too and they said "Can be next hour or in 2023, we cant really tell" but I don't know why

@Owen1212055 Owen1212055 added the build-pr-jar Enables a workflow to build Paperclip jars on the pull request. label Nov 24, 2022
@MiniDigger
Copy link
Member

we are volunteers, we do this in our free time, we can't ever give estimates on anything. we have a giant queue of open PRs that the team is slowly churning thru now (first time below 200 in a looong time!), but it takes time.
on the status of this PR I can say that cat gave this an initial look and concluded that this looks like a good change that we want to have in paper, leaf had some implementation suggestings that seems to have been applied and its now waiting for somebody else on the team to dive into the code, give it a closer look and test it, before it can then be merged.
owen added the fancy build-pr-jar label, that means anybody else can help testing too and report any findings here!

Due to the weakly consistent of ConcurrentLinkedQueue iterator, at some points, packet will be resent twice times or more, causing some weird behaviors (e.g. kicked for illegal movement since the same ClientboundPlayerPositionPacket was sent two times). This changes for the patch add a flag for marking if the packet was consumed to prevent such issue and ensure consistently of the packet queue.
@Owen1212055
Copy link
Member

In the future, please open PRS on other branches as the master branch makes it a little harder for us to work with your PR. 😄

@Owen1212055 Owen1212055 merged commit 28b4027 into PaperMC:master Nov 27, 2022
@sandtechnology
Copy link
Contributor Author

In the future, please open PRS on other branches as the master branch makes it a little harder for us to work with your PR. 😄

Oh, sorry for that, I will create the another branch other than master when opening another PRs.

@Owen1212055
Copy link
Member

No worries, thank you for your contribution regardless.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build-pr-jar Enables a workflow to build Paperclip jars on the pull request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants