Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix segmentation fault when cache sizes are small. #1552

Merged
merged 1 commit into from
Oct 7, 2020

Conversation

martinmr
Copy link
Contributor

@martinmr martinmr commented Oct 1, 2020

If you open a DB with small cache sizes, a segmentation fault happens
because the number of counters in the cache is set to zero, which is not
allowed by Ristretto. Making the value of the variable numInCache to be
at least one fixes the issue.

The stack trace for the segmentation fault is below.

--- FAIL: TestMinCacheSize (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference
[recovered]
        panic: runtime error: invalid memory address or nil pointer
dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x38 pc=0x777e66]

goroutine 6 [running]:
testing.tRunner.func1.1(0x93dc80, 0xc90c60)
        /usr/lib/go/src/testing/testing.go:1076 +0x30d
testing.tRunner.func1(0xc000001b00)
        /usr/lib/go/src/testing/testing.go:1079 +0x41a
panic(0x93dc80, 0xc90c60)
        /usr/lib/go/src/runtime/panic.go:969 +0x175
github.com/dgraph-io/badger/v2.(*DB).stopMemoryFlush(...)
        /home/martinmr/go/src/github.com/dgraph-io/badger/db.go:1561
github.com/dgraph-io/badger/v2.(*DB).cleanup(0x0)
        /home/martinmr/go/src/github.com/dgraph-io/badger/db.go:501
+0x26
github.com/dgraph-io/badger/v2.Open.func4(0xc000157a18, 0xc0000100f0)
        /home/martinmr/go/src/github.com/dgraph-io/badger/db.go:328
+0x45
github.com/dgraph-io/badger/v2.Open(0x0, 0x0, 0x0, 0x0, 0x1, 0x2, 0x2,
0x1, 0x0, 0xa4c760, ...)
        /home/martinmr/go/src/github.com/dgraph-io/badger/db.go:350
+0x1268
github.com/dgraph-io/badger/v2.TestMinCacheSize(0xc000001b00)
        /home/martinmr/go/src/github.com/dgraph-io/badger/db_test.go:2193
+0x1b8
testing.tRunner(0xc000001b00, 0x9d4950)
        /usr/lib/go/src/testing/testing.go:1127 +0xef
created by testing.(*T).Run
        /usr/lib/go/src/testing/testing.go:1178 +0x386
FAIL    github.com/dgraph-io/badger/v2  0.008s

This change is Reviewable

If you open a DB with small cache sizes, a segmentation fault happens
because the number of counters in the cache is set to zero, which is not
allowed by Ristretto. Making the value of the variable numInCache to be
at least one fixes the issue.

The stack trace for the segmentation fault is below.

```
--- FAIL: TestMinCacheSize (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference
[recovered]
        panic: runtime error: invalid memory address or nil pointer
dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x38 pc=0x777e66]

goroutine 6 [running]:
testing.tRunner.func1.1(0x93dc80, 0xc90c60)
        /usr/lib/go/src/testing/testing.go:1076 +0x30d
testing.tRunner.func1(0xc000001b00)
        /usr/lib/go/src/testing/testing.go:1079 +0x41a
panic(0x93dc80, 0xc90c60)
        /usr/lib/go/src/runtime/panic.go:969 +0x175
github.com/dgraph-io/badger/v2.(*DB).stopMemoryFlush(...)
        /home/martinmr/go/src/github.com/dgraph-io/badger/db.go:1561
github.com/dgraph-io/badger/v2.(*DB).cleanup(0x0)
        /home/martinmr/go/src/github.com/dgraph-io/badger/db.go:501
+0x26
github.com/dgraph-io/badger/v2.Open.func4(0xc000157a18, 0xc0000100f0)
        /home/martinmr/go/src/github.com/dgraph-io/badger/db.go:328
+0x45
github.com/dgraph-io/badger/v2.Open(0x0, 0x0, 0x0, 0x0, 0x1, 0x2, 0x2,
0x1, 0x0, 0xa4c760, ...)
        /home/martinmr/go/src/github.com/dgraph-io/badger/db.go:350
+0x1268
github.com/dgraph-io/badger/v2.TestMinCacheSize(0xc000001b00)
        /home/martinmr/go/src/github.com/dgraph-io/badger/db_test.go:2193
+0x1b8
testing.tRunner(0xc000001b00, 0x9d4950)
        /usr/lib/go/src/testing/testing.go:1127 +0xef
created by testing.(*T).Run
        /usr/lib/go/src/testing/testing.go:1178 +0x386
FAIL    github.com/dgraph-io/badger/v2  0.008s
```
@martinmr martinmr merged commit 2245473 into master Oct 7, 2020
@martinmr martinmr deleted the martinmr/min-cache-szie branch October 7, 2020 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants