From 563adc6aaa7bb0b901e7d902fc2aac617f493495 Mon Sep 17 00:00:00 2001 From: m1nl Date: Sun, 1 Mar 2026 00:17:29 +0100 Subject: [PATCH] enhancement(mesh): remove late packets from tx queue when full (#9779) * enhance tx queue priority management In busy environments, especially for ROUTER_LATE role, tx queue fills very quickly. Delayed packets became late but new packets to be retransmitted won't be put into the tx queue as old ones stay there for a very long time (even a minute or more). This change makes meshtastic prioritize new packets over late packets from tx queue and allows to remove late packet from back of tx queue when there is no space for a new one. * apply copilot recommendation for cast --------- Co-authored-by: Ben Meadors --- src/mesh/MeshPacketQueue.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/mesh/MeshPacketQueue.cpp b/src/mesh/MeshPacketQueue.cpp index cbea85c62..4aad40c69 100644 --- a/src/mesh/MeshPacketQueue.cpp +++ b/src/mesh/MeshPacketQueue.cpp @@ -184,6 +184,29 @@ bool MeshPacketQueue::replaceLowerPriorityPacket(meshtastic_MeshPacket *p) } } + if (backPacket->tx_after) { + // Check if there's a late packet at the queue end + auto now = millis(); + if (backPacket->tx_after < now && (!p->tx_after || backPacket->tx_after > p->tx_after)) { + int32_t dt = (int32_t)(backPacket->tx_after - now); + if (p->tx_after) { + LOG_WARN("Dropping late packet 0x%08x with TX delay %dms to make room in the TX queue for packet 0x%08x with " + "TX delay %ums", + backPacket->id, dt, p->id, p->tx_after - now); + + } else { + LOG_WARN("Dropping late packet 0x%08x with TX delay %dms to make room in the TX queue for packet 0x%08x " + "with no TX delay", + backPacket->id, dt, p->id); + } + queue.pop_back(); + packetPool.release(backPacket); + // Insert the new packet in the correct order + enqueue(p); + return true; + } + } + // If the back packet's priority is not lower, no replacement occurs return false; } \ No newline at end of file