From ea564d489f2cb8b43c6ea1c90eb40bbcf39ebc63 Mon Sep 17 00:00:00 2001 From: Ales Raszka Date: Thu, 19 Nov 2020 10:40:46 +0100 Subject: [PATCH] Direct-delivery: Fix slices in direct notifier There was a bug in direct notifier that caused only subset of notification was sent to client. The first iteration over notification replaced original notification slice with just first "page". This caused that only one "page" was sent and rest was ignored. This commit fixes amqp and stomp direct notification delivery. Signed-off-by: Ales Raszka --- notifier/amqp/directdeliverer.go | 5 +++-- notifier/stomp/directdeliverer.go | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/notifier/amqp/directdeliverer.go b/notifier/amqp/directdeliverer.go index 78412ee1f4..ac8ff3bab6 100644 --- a/notifier/amqp/directdeliverer.go +++ b/notifier/amqp/directdeliverer.go @@ -85,6 +85,7 @@ func (d *DirectDeliverer) Deliver(ctx context.Context, _ uuid.UUID) error { var buf bytes.Buffer enc := json.NewEncoder(&buf) + var currentBlock []notifier.Notification for bs, be := 0, rollup; bs < len(d.n); bs, be = be, be+rollup { buf.Reset() // if block-end exceeds array bounds, slice block underflow. @@ -93,8 +94,8 @@ func (d *DirectDeliverer) Deliver(ctx context.Context, _ uuid.UUID) error { be = len(d.n) } - d.n = d.n[bs:be] - err := enc.Encode(&d.n) + currentBlock = d.n[bs:be] + err := enc.Encode(¤tBlock) if err != nil { ch.TxRollback() return &clairerror.ErrDeliveryFailed{err} diff --git a/notifier/stomp/directdeliverer.go b/notifier/stomp/directdeliverer.go index 598b1dc3b6..a9ed94fef2 100644 --- a/notifier/stomp/directdeliverer.go +++ b/notifier/stomp/directdeliverer.go @@ -75,6 +75,7 @@ func (d *DirectDeliverer) Deliver(ctx context.Context, nID uuid.UUID) error { var buf bytes.Buffer enc := json.NewEncoder(&buf) + var currentBlock []notifier.Notification for bs, be := 0, rollup; bs < len(d.n); bs, be = be, be+rollup { buf.Reset() // if block-end exceeds array bounds, slice block underflow. @@ -83,8 +84,8 @@ func (d *DirectDeliverer) Deliver(ctx context.Context, nID uuid.UUID) error { be = len(d.n) } - d.n = d.n[bs:be] - err := enc.Encode(&d.n) + currentBlock = d.n[bs:be] + err := enc.Encode(¤tBlock) if err != nil { tx.Abort() return &clairerror.ErrDeliveryFailed{err}