Skip to content

Commit

Permalink
Direct-delivery: Fix slices in direct notifier
Browse files Browse the repository at this point in the history
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 <araszka@redhat.com>
  • Loading branch information
Allda authored and ldelossa committed Nov 19, 2020
1 parent f4169c4 commit ea564d4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions notifier/amqp/directdeliverer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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(&currentBlock)
if err != nil {
ch.TxRollback()
return &clairerror.ErrDeliveryFailed{err}
Expand Down
5 changes: 3 additions & 2 deletions notifier/stomp/directdeliverer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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(&currentBlock)
if err != nil {
tx.Abort()
return &clairerror.ErrDeliveryFailed{err}
Expand Down

0 comments on commit ea564d4

Please sign in to comment.