From 4d663b749b4ff7858856c64eb1e6447df789e4d4 Mon Sep 17 00:00:00 2001 From: Conny Andersson Date: Mon, 8 May 2023 10:05:26 +0200 Subject: [PATCH] Release device and gateway locks if nothing to send for class C --- internal/downlink/data/data.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/internal/downlink/data/data.go b/internal/downlink/data/data.go index 90fc4d436..97b68c282 100644 --- a/internal/downlink/data/data.go +++ b/internal/downlink/data/data.go @@ -1266,6 +1266,20 @@ func stopOnNothingToSend(ctx *dataContext) error { // in reply to a confirmed-uplink and no requirement to send an empty downlink // (e.g. in case of ADRACKReq). if ctx.DeviceQueueItem == nil && len(ctx.MACCommands) == 0 && !ctx.ACK && !ctx.MustSend { + if ctx.DeviceMode == storage.DeviceModeC { + // If we made it this far for a class C device we most certainly own + // the device and gateway locks so make sure to release them before returning. + key := storage.GetRedisKey(deviceDownlinkLockKey, ctx.DeviceSession.DevEUI) + _ = storage.RedisClient().Del(ctx.ctx, key).Err() + + if classCGatewayDownlinkLockDuration != 0 { + var id lorawan.EUI64 + copy(id[:], ctx.DownlinkFrame.GatewayId) + key := storage.GetRedisKey(gatewayDownlinkLockKey, id) + _ = storage.RedisClient().Del(ctx.ctx, key).Err() + } + } + // ErrAbort will not be handled as a real error return ErrAbort }