fix(server): repair Pending lastSeen acknowledgement bookkeeping - #1537
Open
GoatTech-42 wants to merge 2 commits into
Open
GoatTech-42 wants to merge 2 commits into
GoatTech-42 wants to merge 2 commits into
Conversation
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.
Fixes #1535.
The reported bug:
Pending.setPreviouslyAcknowledged()stored the return value ofArray.prototype.push()(a length) instead of the array, so the next validation threwTypeError: this.lastSeen.some is not a function.While writing a regression test for it, three more bugs surfaced in the same
Pendingacknowledgement path (src/server/chat.js, used for 1.19.1/1.19.2 servers withenforceSecureProfile) - each one alone breaks the flow before the reported line is even reached, so the PR fixes all four:validateLastMessagescalledpending.get(messageSender)(messageSignature)- a curried call on a two-argument method.pending.get(...)returns a timestamp orundefined, so any first-time acknowledgement entry threwTypeError: pending.get(...) is not a function. Nowpending.get(messageSender, messageSignature).setPreviouslyAcknowledged(the reported bug) - now builds the array directly and only appends the rejected entry when it is non-empty:Signatures were compared by identity (
===) inpreviouslyAcknowledged,acknowledge, andacknowledgePrior. Packet signatures are freshly parsedBuffers per message, so a client repeating a previously acknowledged entry could never match - exactly the casesetPreviouslyAcknowledgedexists to allow. Added asignaturesEqualhelper that usesBuffer.equalswhen both sides are buffers. This also fixesacknowledge'sfindIndexreturning-1andsplice(-1, 1)silently dropping the newest pending entry when alastRejectedsignature didn't identity-match.acknowledgePriordeletedthis.m[a](a sender's whole timestamp map) and calledthis.splice(0, i), which leaves the matched entry itself in the pending list. It now finds the match first, deletes only the covered per-signature entries, and splicesindex + 1entries.Regression tests in
test/chatPendingTest.jsdrive the realchat_messagehandler across two packets: a repeated acknowledgement (re-parsed buffer, same bytes) must be accepted, a message the server never sent must still disconnect withmultiplayer.disconnect.chat_validation_failed. On current master the first test fails on the very first packet (bug 1); with bug 1 fixed alone it fails on the second packet (the reported bug 2, then bug 3).Lint (
standard) passes; the new tests pass against the fixed code and fail against master.