spicedb icon indicating copy to clipboard operation
spicedb copied to clipboard

fix panic on cached optimized revisions

Open vroldanbet opened this issue 3 years ago • 0 comments

What

This PR fixes a panic that sometimes triggered when database connection errors happened during the computation of optimized revisions through the singleflight wrapper.

Why

Any error happening in the optimized revision function executed through the singleflight group was unhandled, which led lastQuantizedRevision.(decimal.Decimal) type assertion to panic:

https://github.com/authzed/spicedb/blob/ae4552ed89f0561f71893da2feeb7feb1e767e71/internal/datastore/common/revisions/optimized.go#L72

panic: interface conversion: interface {} is nil, not decimal.Decimal

How

By adding good old if err != nil ... 😄

vroldanbet avatar Aug 10 '22 11:08 vroldanbet