bmatsuo/lmdb-go

lmdb: possible CGO pointer argument panic using bytes.Buffer

bmatsuo opened this issue · 1 comments

My experimental raft backend at github.com/bmatsuo/raft-mdb issues a panic due to the new cgo pointer restrictions. The problem occurs when a bytes.Buffer with a small amount of data is written using the Bytes method.

$ go test
--- FAIL: TestMDB_Logs (0.00s)
panic: runtime error: cgo argument has Go pointer to Go pointer [recovered]
    panic: runtime error: cgo argument has Go pointer to Go pointer

goroutine 11 [running]:
panic(0x896ec0, 0xc82000bc00)
    /usr/lib/go/src/runtime/panic.go:464 +0x3e6
testing.tRunner.func1(0xc8200805a0)
    /usr/lib/go/src/testing/testing.go:467 +0x192
panic(0x896ec0, 0xc82000bc00)
    /usr/lib/go/src/runtime/panic.go:426 +0x4e9
github.com/bmatsuo/lmdb-go/lmdb._cgoCheckPointer0(0x7d23c0, 0xc8200541e4, 0x0, 0x0, 0x0, 0xc82000bba8)
    ??:0 +0x4d
github.com/bmatsuo/lmdb-go/lmdb.(*Txn).Put(0xc8200c1f40, 0xc800000002, 0xc82000bba8, 0x8, 0x8, 0xc8200541e4, 0x1f, 0x40, 0x0, 0x0, ...)
    /home/b/src/github.com/bmatsuo/lmdb-go/lmdb/txn.go:297 +0x19d
github.com/bmatsuo/raft-mdb.(*MDBStore).StoreLogs.func1(0xc8200c1f40, 0x0, 0x0)
    /home/b/src/github.com/bmatsuo/raft-mdb/mdb_store.go:180 +0x31d
github.com/bmatsuo/lmdb-go/lmdb.(*Env).run(0xc8200280f0, 0x489301, 0x0, 0xc820049b90, 0x0, 0x0)
    /home/b/src/github.com/bmatsuo/lmdb-go/lmdb/env.go:461 +0x16a
github.com/bmatsuo/lmdb-go/lmdb.(*Env).Update(0xc8200280f0, 0xc820049b90, 0x0, 0x0)
    /home/b/src/github.com/bmatsuo/lmdb-go/lmdb/env.go:437 +0x45
github.com/bmatsuo/raft-mdb.(*MDBStore).StoreLogs(0xc820116600, 0xc820049bf0, 0x1, 0x1, 0x0, 0x0)
    /home/b/src/github.com/bmatsuo/raft-mdb/mdb_store.go:186 +0x63
github.com/bmatsuo/raft-mdb.(*MDBStore).StoreLog(0xc820116600, 0xc820015c80, 0x0, 0x0)
    /home/b/src/github.com/bmatsuo/raft-mdb/mdb_store.go:164 +0x84
github.com/bmatsuo/raft-mdb.TestMDB_Logs(0xc8200805a0)
    /home/b/src/github.com/bmatsuo/raft-mdb/mdb_store_test.go:167 +0x944
testing.tRunner(0xc8200805a0, 0xd85f40)
    /usr/lib/go/src/testing/testing.go:473 +0x98
created by testing.RunTests
    /usr/lib/go/src/testing/testing.go:582 +0x892
exit status 2
FAIL    github.com/bmatsuo/raft-mdb 0.006s

The solution is that the cgo callsite must actually contain a slice addressing operation for the tool to properly detect that the slice is being addressed and not the bytes.Buffer containing the slice. I have a branch with a fix. But I am concerned that there is a performance impact on resulting binaries.