Fix grant_immediate overwriting active read grants#78
Merged
Conversation
grant_immediate() forcibly evicts front messages from the ring buffer without checking read_in_progress. When a subscriber holds a FrameGrantR (raw pointer into the buffer), the evicted region gets overwritten by the new message, causing data corruption. Changes: - grant_immediate: check read_in_progress on front message before evicting; return Err(InsufficientSize) when the front is held by a reader. The caller (stack.rs) already handles this by discarding the incoming publish and skipping PUBACK, so the broker redelivers. - free_space / grant_with_context: fix off-by-one in inverted check (< to <=). When back_end == front.start the buffer is full, not empty. - Add regression test: grant_immediate_refuses_to_evict_read_in_progress
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.
Summary
grant_immediate()forcibly evicts front messages from the ring buffer without checkingread_in_progress. When a subscriber holds aFrameGrantR(raw pointer into the buffer), the evicted region gets overwritten by the new message, causing data corruption. This manifests as intermittent hash mismatches in rustot's OTA integration test.read_in_progresson the front message before evicting. ReturnsErr(InsufficientSize)when the front is held by a reader. The caller (stack.rs:238-254) already handles this error by discarding the incoming publish and skipping PUBACK — the broker redelivers for QoS 1.free_space()andgrant_with_context(): whenback_end == front.start(buffer wraps to exactly touch the front), this was incorrectly treated as non-inverted, returning a wildly inflated free space value.Test plan
grant_immediate_refuses_to_evict_read_in_progress