remove dead packages even if no new messages exist
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 1m53s

This commit is contained in:
matst80
2024-11-10 11:41:30 +01:00
parent 9d3d61bd83
commit 015e9d8d48

View File

@@ -43,14 +43,18 @@ func NewPacketQueue(connection net.Conn) *PacketQueue {
queue.mu.Lock()
now := time.Now().Add(-time.Millisecond * 500)
keepIndex := -1
for i, packet := range queue.Packets {
if packet.Added.After(now) {
stillInQueue := queue.Packets[i:]
log.Printf("DEBUG: Requeueing %d packets\n", len(stillInQueue))
queue.Packets = stillInQueue
keepIndex = i
break
}
}
if keepIndex == -1 {
queue.Packets = queue.Packets[:0]
} else {
queue.Packets = queue.Packets[keepIndex:]
}
queue.Packets = append(queue.Packets, PacketWithData{
MessageType: messageType,
Added: ts,