spicedb
spicedb copied to clipboard
fix panic on cached optimized revisions
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 ... 😄