Conversation
Requesting the same cookie more than once before the client answered replaced the earlier pending request, so its future never completed and the extra response kicked the player. Pending requests are now queued per key and completed in the order they were sent. Fixes PaperMC#14211
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.
Bug
Calling
retrieveCookie()for the same key multiple times before the client responds caused the pending request to be overwritten. Because the map only stored one request per key, the first future never completed, and the player was kicked withunexpected query response.Changed
Each cookie key now stores a queue of pending requests, so responses are matched in the same order as the requests were sent. This approach was suggested by electronicboy on the issue.
Adding and removing requests from the queue are done as a single map operation. The future is also removed from the queue before being completed, so requesting the same cookie again from a callback works correctly.
Testing
Added
ReadablePlayerCookieConnectionImplTestwith 4 test cases. The tests for requesting the same key twice and requesting it again from a callback fail on the old code and pass with this fix.I also tested it manually on a 26.2 client with a test command that requests the same cookie 3 times. Before the fix, only the last request completed and the player got kicked. After the fix, all 3 requests completed and the player stayed connected.
Fixes #14211
I used Claude to help write the fix and tests, and I reviewed and tested the changes myself.