Skip to content

Commit 72079c7

Browse files
committed
GOCBC-1828: Ensure that any initial fatal range scan errors are returned immediately
Motivation ========== When there is a fatal error from the initial scan create calls, cancelCh is closed, followed by the resultCh once all worker goroutines are stopped. However, when the relevant select statement that waits for either is called, depending on the timing, they can both be closed, in which case one of the two cases is selected at random. This can result in either getting the error immediately from the Collection.Scan call (which is the intended behaviour), or returning a ScanResult that has its error field populated. So the error will still be returned to the user, but at a different point. Changes ======= * Only wait for the resultCh to either be closed or have a value before returning from the Collection.Scan call. When the range scan is canceled, resultCh will also be closed. * If we do not receive at item from resultCh, then check if we have a fatal error from the range scan and return it. This is equivalent to the original intended behaviour, but ensures that we always return the error immediately when it is present. Change-Id: Ie713546e73820527fc36679eb702b0233b418707 Reviewed-on: https://review.couchbase.org/c/gocb/+/245725 Tested-by: Build Bot <build@couchbase.com> Reviewed-by: Charles Dixon <chvckd@gmail.com>
1 parent 5badc84 commit 72079c7

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

rangescanopmanager.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -471,14 +471,12 @@ func (m *rangeScanOpManager) Scan(ctx context.Context) (*ScanResult, error) {
471471
}()
472472
}
473473
// Block waiting for any errors on the first scan(s) so that we can immediately return that error.
474-
select {
475-
case <-m.cancelCh:
476-
return nil, r.Err()
477-
case item, more := <-resultCh:
478-
// more could be false if no sampling scans returned any data, but that isn't an error case.
479-
if more {
480-
r.peeked.Store(item)
481-
}
474+
item, more := <-resultCh
475+
// more could be false if no sampling scans returned any data, but that isn't an error case.
476+
if more {
477+
r.peeked.Store(item)
478+
} else if err := r.Err(); err != nil {
479+
return nil, err
482480
}
483481

484482
return r, nil

0 commit comments

Comments
 (0)