Skip to content

Commit

Permalink
MB-57871: Recover panic by GetCardinality
Browse files Browse the repository at this point in the history
+ roaring.Bitmap's GetCardinality method is causing panic.
+ Panic logs are indicating towards a roaring container being nil.
+ Which shouldn't be the case and we aren't able to reproduce this to
  know what operations on bitap lead us to this state.

+ This change intends to add panic recovery and logging bitmap related
  stats in case of panic to better equip us in reasoning about the panic.
  • Loading branch information
moshaad7 committed Sep 17, 2024
1 parent e148470 commit c3fd952
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions posting.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package zap
import (
"encoding/binary"
"fmt"
"log"
"math"
"reflect"

Expand Down Expand Up @@ -240,6 +241,23 @@ func (p *PostingsList) Count() uint64 {
e = 1
}
} else if p.postings != nil {
// A safeguard against panic by roaring.Bitmap.GetCardinality()
//
// See https://jira.issues.couchbase.com/browse/MB-57871
//
// A panic was observed in the wild in Bitmap.GetCardinality(),
// because of a nil pointer dereference, that happened due to
// presence of a nil container in the Bitmap.highlowcontainer.containers
//
// This is a temporary fix to help us recover from the panic, and to
// log bitmap stats to help us understand the issue better.
defer func() {
if r := recover(); r != nil {
log.Printf("zapx: PostingsList.Count() panic: %v"+
"\n\nBitmap Stats:%+v\n", r, p.postings.Stats())
}
}()

n = p.postings.GetCardinality()
if p.except != nil {
e = p.postings.AndCardinality(p.except)
Expand Down

0 comments on commit c3fd952

Please sign in to comment.