Concurrent Access Issue with freezeblocks.BlockReader leading to Runtime Panic
Closed this issue · 4 comments
I encountered a runtime panic when using four threads to concurrently access block hashes with the freezeblocks.BlockReader. The error seems to relate to a CGO pointer issue. Below is the error message that was produced during execution:
panic: runtime error: cgo argument has Go pointer to unpinned Go pointer
goroutine 32 [running]:
github.com/erigontech/mdbx-go/mdbx.(*Cursor).getVal1.func1(0xc0ccfb3d00?, 0xc0ccf02900, {0xc0ccf02900?, 0x28, 0x0?}, 0xf)
/home/wulab/go/pkg/mod/github.com/erigontech/mdbx-go@v0.27.24/mdbx/cursor.go:210 +0x7a
github.com/erigontech/mdbx-go/mdbx.(*Cursor).getVal1(0xc0ccf46b08?, {0xc0ccf02900?, 0x0?, 0x0?}, 0xc0ccf46b08?)
/home/wulab/go/pkg/mod/github.com/erigontech/mdbx-go@v0.27.24/mdbx/cursor.go:211 +0x38
github.com/erigontech/mdbx-go/mdbx.(*Cursor).Get(0xc0b7ed5c60, {0xc0ccf02900, 0x28, 0x28}, {0x0?, 0x1ae29b0?, 0x16?}, 0xf)
/home/wulab/go/pkg/mod/github.com/erigontech/mdbx-go@v0.27.24/mdbx/cursor.go:156 +0x74
github.com/ledgerwatch/erigon-lib/kv/mdbx.(*MdbxCursor).set(...)
/home/wulab/erigon/erigon-lib/kv/mdbx/kv_mdbx.go:1195
github.com/ledgerwatch/erigon-lib/kv/mdbx.(*MdbxCursor).SeekExact(0xc00007c4e0?, {0xc0ccf02900?, 0x6?, 0xc0ccf46b01?})
/home/wulab/erigon/erigon-lib/kv/mdbx/kv_mdbx.go:1544 +0x230
github.com/ledgerwatch/erigon-lib/kv/mdbx.(*MdbxTx).GetOne(0x7f72923775b8?, {0x16a8918?, 0xc000100808?}, {0xc0ccf02900, 0x28, 0x28})
/home/wulab/erigon/erigon-lib/kv/mdbx/kv_mdbx.go:1043 +0x57
github.com/ledgerwatch/erigon/core/rawdb.ReadHeaderRLP({0x72f1536f5458, 0xc00007c4e0}, {0x30, 0xd8, 0x3f, 0x61, 0xc, 0xa3, 0x82, 0xe1, ...}, ...)
/home/wulab/erigon/core/rawdb/accessors_chain.go:252 +0xc2
github.com/ledgerwatch/erigon/core/rawdb.ReadHeader({0x72f1536f5458?, 0xc00007c4e0?}, {0x30, 0xd8, 0x3f, 0x61, 0xc, 0xa3, 0x82, 0xe1, ...}, ...)
/home/wulab/erigon/core/rawdb/accessors_chain.go:261 +0x48
github.com/ledgerwatch/erigon/turbo/snapshotsync/freezeblocks.(*BlockReader).Header(0xc0b061a7a0, {0x60?, 0x4?}, {0x72f1536f5458?, 0xc00007c4e0?}, {0x30, 0xd8, 0x3f, 0x61, 0xc, ...}, ...)
/home/wulab/erigon/turbo/snapshotsync/freezeblocks/block_reader.go:437 +0x79
This issue occurred while trying to read headers using the BlockReader.Header function. Here is the initialization snippet for the BlockReader used in my setup:
func newBlockReader(cfg ethconfig.Config) *freezeblocks.BlockReader {
var minFrozenBlock uint64
if frozenLimit := cfg.Sync.FrozenBlockLimit; frozenLimit != 0 {
if maxSeedable := snapcfg.MaxSeedableSegment(cfg.Genesis.Config.ChainName, SNAPSHOT); maxSeedable > frozenLimit {
minFrozenBlock = maxSeedable - frozenLimit
}
}
blockSnaps := freezeblocks.NewRoSnapshots(cfg.Snapshot, SNAPSHOT, minFrozenBlock, log.New())
borSnaps := freezeblocks.NewBorRoSnapshots(cfg.Snapshot, SNAPSHOT, minFrozenBlock, log.New())
blockSnaps.ReopenFolder()
borSnaps.ReopenFolder()
return freezeblocks.NewBlockReader(blockSnaps, borSnaps)
}
Configuration used: cfg = ethconfig.Defaults.
I would appreciate any insights or suggestions on how to address this error. Is there a known issue with concurrent access or a specific setup that I should follow to avoid this panic? Any guidance or updates on resolving this error would be greatly appreciated.
Thank you!
can't move tx
object between goroutines
Can I do dbTx, _ := db.BeginRo(ctx)
in different goroutines with a same db
?
can. must check err
Thank u, it helps a lot!