From 19b668c3e4501522ce3ebe125045ee315709a373 Mon Sep 17 00:00:00 2001 From: Adrian-Stefan Mares Date: Tue, 25 Jul 2023 15:55:09 +0200 Subject: [PATCH] all: Avoid watching empty sets of keys --- pkg/applicationserver/redis/registry.go | 9 +++++++-- pkg/joinserver/redis/registry.go | 9 +++++++-- pkg/networkserver/redis/registry.go | 9 +++++++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/pkg/applicationserver/redis/registry.go b/pkg/applicationserver/redis/registry.go index b523063a2d..63738d3aec 100644 --- a/pkg/applicationserver/redis/registry.go +++ b/pkg/applicationserver/redis/registry.go @@ -505,8 +505,13 @@ func (r *DeviceRegistry) BatchDelete( } } } - if err := tx.Watch(ctx, euiKeys...).Err(); err != nil { - return err + // If the provided end device identifiers are not registered, it is possible + // that the `euiKeys` set will be empty. `WATCH` does not allow an empty set + // of keys to be provided, and as such must be manually skipped. + if len(euiKeys) > 0 { + if err := tx.Watch(ctx, euiKeys...).Err(); err != nil { + return err + } } if _, err := tx.TxPipelined(ctx, func(p redis.Pipeliner) error { p.Del(ctx, append(uidKeys, euiKeys...)...) diff --git a/pkg/joinserver/redis/registry.go b/pkg/joinserver/redis/registry.go index 03bf06abf5..2b75317fdd 100644 --- a/pkg/joinserver/redis/registry.go +++ b/pkg/joinserver/redis/registry.go @@ -879,8 +879,13 @@ func (r *DeviceRegistry) BatchDelete( } } } - if err := tx.Watch(ctx, keys...).Err(); err != nil { - return err + // If the provided end device identifiers are not registered, it is possible + // that the `keys` set will be empty. `WATCH` does not allow an empty set of + // keys to be provided, and as such must be manually skipped. + if len(keys) > 0 { + if err := tx.Watch(ctx, keys...).Err(); err != nil { + return err + } } if _, err := tx.TxPipelined(ctx, func(p redis.Pipeliner) error { p.Del(ctx, append(uidKeys, keys...)...) diff --git a/pkg/networkserver/redis/registry.go b/pkg/networkserver/redis/registry.go index 46c63dac69..2eab68fe25 100644 --- a/pkg/networkserver/redis/registry.go +++ b/pkg/networkserver/redis/registry.go @@ -1024,8 +1024,13 @@ func (r *DeviceRegistry) BatchDelete( } } } - if err := tx.Watch(ctx, euiKeys...).Err(); err != nil { - return err + // If the provided end device identifiers are not registered, it is possible + // that the `euiKeys` set will be empty. `WATCH` does not allow an empty set + // of keys to be provided, and as such must be manually skipped. + if len(euiKeys) > 0 { + if err := tx.Watch(ctx, euiKeys...).Err(); err != nil { + return err + } } if _, err := tx.TxPipelined(ctx, func(p redis.Pipeliner) error { p.Del(ctx, append(uidKeys, euiKeys...)...)