Fix countBefore regression: replace sentinel with getOutboundTotal()#1877
Open
DanielNovak wants to merge 2 commits intomeshcore-dev:devfrom
Open
Fix countBefore regression: replace sentinel with getOutboundTotal()#1877DanielNovak wants to merge 2 commits intomeshcore-dev:devfrom
DanielNovak wants to merge 2 commits intomeshcore-dev:devfrom
Conversation
Author
|
Sorry for breaking this, I should have checked the callers of that function for any special constants :-/. |
PR meshcore-dev#1795 changed PacketQueue::countBefore() to use signed 2's complement arithmetic for millis wraparound safety. However, this broke the 0xFFFFFFFF sentinel pattern used by callers to mean "count all packets regardless of schedule". With the signed comparison, countBefore(0xFFFFFFFF) always returns 0, causing hasPendingWork() to report false and repeaters to sleep with packets still queued. Stats reporting also shows queue_len as 0. Add an early-return for the sentinel value before the loop, and document the sentinel convention on the virtual interface and implementation.
c8c7165 to
c436bd4
Compare
Contributor
|
Instead of continuing to use the error prone magic number int PacketQueue::count() const {
return _num;
}And then replacing |
Author
|
Definitely better. I just didn't want to make the surface of the change bigger - but I guess it makes sense to do it now because someone else will step on this again :). I will push the commit in few minutes. |
Instead of overloading getOutboundCount() with a magic sentinel value, add a dedicated getOutboundTotal() method to the PacketManager interface that returns the total queue size without time filtering. This eliminates the fragile convention that caused the regression and makes the two operations — time-filtered count vs total count — explicitly separate in the API.
Contributor
|
Even better: @DanielNovak Thanks! Looks good to me now! |
fschrempf
approved these changes
Feb 28, 2026
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
PR #1795 introduced a millis wraparound fix in
PacketQueue::countBefore(), changing the comparison from unsigned to signed 2's complement arithmetic:This correctly handles millis wraparound (~49.7 day rollover), but broke the
0xFFFFFFFFsentinel pattern used by callers to mean "count all packets regardless of schedule". With the signed comparison,countBefore(0xFFFFFFFF)always returns 0.As noted in #1795 and #1687, this causes:
hasPendingWork()to always returnfalse— repeaters sleep with packets still queuedqueue_len = 0Fix
Rather than patching the sentinel with a special case, this PR adds a dedicated
getOutboundTotal()method to thePacketManagerinterface that returns the total queue size viaPacketQueue::count(), without any time filtering.All 5 call sites that previously passed
0xFFFFFFFFnow use the new method:examples/simple_repeater/MyMesh.cpp—hasPendingWork()+ repeater statsexamples/simple_room_server/MyMesh.cpp— server statusexamples/companion_radio/MyMesh.cpp— companion statssrc/helpers/StatsFormatHelper.h— core stats JSONThis makes the two operations explicit in the API:
getOutboundCount(now)— count packets scheduled at or before timenowgetOutboundTotal()— count all queued packetsImpact
getOutboundTotal()returns_numdirectly, avoiding the loopPacketManager. Out-of-tree implementations will get a compile error guiding them to add it.StaticPoolPacketManageris the only implementation in-tree.