Fix #1076: compact ActiveSubs array in TO_LAB_RemovePacketCmd to prev… - #237
Open
Adityakk9031 wants to merge 1 commit into
Open
Fix #1076: compact ActiveSubs array in TO_LAB_RemovePacketCmd to prev…#237Adityakk9031 wants to merge 1 commit into
Adityakk9031 wants to merge 1 commit into
Conversation
…ent slot desync Previously, TO_LAB_RemovePacketCmd() zeroed the removed slot and decremented ActiveSubCount without compacting the array. This left holes at lower indices while TO_LAB_AddPacketCmd() always wrote new entries at ActiveSubs[ActiveSubCount], causing it to overwrite valid existing subscriptions and eventually report false capacity exhaustion even when reusable slots were available. Fix: after a successful unsubscribe, move the last active entry (ActiveSubs[ActiveSubCount - 1]) into the freed slot (ActiveSubsIndex) and clear the tail. This maintains the invariant that ActiveSubs[0..ActiveSubCount-1] is always contiguous and fully occupied, keeping ActiveSubCount synchronized with actual usage. Root cause: - AddPacket gated on ActiveSubCount >= MAX but wrote to ActiveSubs[ActiveSubCount], assuming the array is contiguous. - RemovePacket left holes, breaking the contiguous assumption. Effects before fix (dynamically reproduced): - Subscription 0x8fb reported missing despite not being explicitly removed (overwritten by a subsequent AddPacket call). - 0x9e0 rejected with max subscriptions reached while cleared holes still existed in the array. Closes nasa/cFS#1076
2 tasks
Author
|
@elizabash and @jphickey have a look |
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
Fixes an externally-triggerable state-machine desynchronization in TO_LAB where
ActiveSubCountcould diverge from the actual reusable occupancy ofActiveSubs[], causing valid subscription tracking loss and false capacity exhaustion.Closes nasa/cFS#1076
Problem
TO_LAB_AddPacketCmd()andTO_LAB_RemovePacketCmd()maintained the dynamic subscription table inconsistently.AddPacket (
to_lab_cmds.c)ActiveSubCount >= TO_LAB_MISSION_MAX_SUBSCRIPTIONSActiveSubs[ActiveSubCount](assumes array is contiguous)ActiveSubCountRemovePacket (
to_lab_cmds.c)ActiveSubCountActiveSubsIndexConsequence
After one or more removals, holes existed at lower indices while
AddPacketkept appending only at the tail (ActiveSubs[ActiveSubCount]), overwriting valid existing subscriptions that were still active. EventuallyActiveSubCountreachedMAXwhile reusable cleared slots still existed, causing:Dynamically Reproduced Evidence (from issue report)
The removed packets create low-index holes. Subsequent additions continue writing at the tail, eventually overwriting active subscriptions. Later, valid subscriptions appear missing even though they were never explicitly removed, and new subscriptions are rejected despite available reusable slots.
Fix
In
TO_LAB_RemovePacketCmd(), after a successfulCFE_SB_Unsubscribe, compact the array by moving the last active entry into the freed slot, then clearing the old tail.This maintains the invariant:
ActiveSubs[0 .. ActiveSubCount - 1]is always contiguous and fully occupied.ActiveSubs[ActiveSubCount ..]is always zero/invalid.Since
AddPacketwrites toActiveSubs[ActiveSubCount], it is now guaranteed to always write to a genuinely empty slot without colliding with any active subscription.Verification
ActiveSubs[i] = ActiveSubs[i]is a benign no-opTO_LAB_RemoveAllCmdinteractionAddPacketCmdCFE_SB_ValueToMsgId(0), so they never match a valid streamRelated
fsw/src/to_lab_cmds.cTO_LAB_RemovePacketCmd()