Duplicated downlink packets

We are seeing duplicated downlink unconfirmed packets like these:
rcai@westgate:~/test$ cat loraNet_apr03.txt| grep JSON|grep txpk|cut -d: -f19
“IJY4bM3Q2WZGr96s8uzXIbA=”}}
“YN2kaACqAAADAAEAcAMw/wABdh0HUA==”}}
“YN2kaACqAAADAAEAcAMx/wABKlednA==”}}
“YN2kaACqAQADAAEAcAMx/wABh/Or+w==”}}
“YN2kaACqAgADAAEAcAMx/wABl6r2Lw==”}}
“YN2kaACgAwAKGgOZ”}}
“YN2kaACgBACD+m3/”}}
“YN2kaACgBQCrJjte”}}
“YN2kaACgBgDDHeYL”}}
“YN2kaACgBgDDHeYL”}}
“YN2kaACgBgDDHeYL”}}
“YN2kaACgBwDNNNm8”}}
“YN2kaACgCABPLFi9”}}
“YN2kaACgCABPLFi9”}}
“YN2kaACgCQBa/a93”}}
“YN2kaACgCgBUNHHc”}}
“YN2kaACgCwBVN91s”}}
“YN2kaACgDAC8DCmt”}}
“YN2kaACgDQC7rL7x”}}
rcai@westgate:~/test$

Investigation shows that in the responseTasks tasks, the ACK of sendDownlinkFrame sometimes come back before saveDownlinkFrame is finishe, so ack.HandleDownlinkTXAck fails since it tries to retrieve the downlink frame that hasn’t been saved. Subsequently, the remaining tasks such as FCnt increments and sending uplink meta-data to network-controller are dropped. When FCnt fails to increase, you get duplicated downlink packets.

The following patch seems to solve the problem :

diff --git a/internal/downlink/data/data.go b/internal/downlink/data/data.go
index 6c91ae3..4659c65 100644
--- a/internal/downlink/data/data.go
+++ b/internal/downlink/data/data.go
@@ -35,6 +35,8 @@ import (
        "github.com/brocaar/lorawan/backend"
        loraband "github.com/brocaar/lorawan/band"
        "github.com/brocaar/lorawan/sensitivity"
+
+       "runtime/debug"
 )

 const (
@@ -124,14 +126,14 @@ var responseTasks = []func(*dataContext) error{
        setMACCommandsSet,
        stopOnNothingToSend,
        setPHYPayloads,
+       saveDeviceSession,
+       saveDownlinkFrame,
        isRoaming(false,
                sendDownlinkFrame,
        ),
        isRoaming(true,
                sendDownlinkFramePassiveRoaming,
        ),
-       saveDeviceSession,
-       saveDownlinkFrame,
        isRoaming(true,
                handleRoamingTxAck,
        ),

I just want to check if this is something known or already fixed.
If not will my fix cause other problems?

This was fixed in downlink tasks order changed: first save frame, then send it. No avoi… · brocaar/chirpstack-network-server@2a287fa · GitHub :slight_smile:

2 Likes