trying to fix memory leak

This commit is contained in:
Jeffrey Picard 2022-04-14 00:25:37 +00:00
parent 8cb0d1fdb8
commit f9011c7d52
5 changed files with 23 additions and 6 deletions

View file

@ -332,8 +332,10 @@ func IterCF(db *grocksdb.DB, opts *IterOptions) <-chan *prefixes.PrefixRowKV {
} }
go func() { go func() {
defer it.Close() defer func() {
defer close(ch) it.Close()
close(ch)
}()
var prevKey []byte var prevKey []byte
// FIXME: There's messy uses of kv being nil / not nil here. // FIXME: There's messy uses of kv being nil / not nil here.

View file

@ -44,6 +44,7 @@ func (db *ReadOnlyDBColumnFamily) GetBlockHash(height uint32) ([]byte, error) {
key := prefixes.NewBlockHashKey(height) key := prefixes.NewBlockHashKey(height)
rawKey := key.PackKey() rawKey := key.PackKey()
slice, err := db.DB.GetCF(db.Opts, handle, rawKey) slice, err := db.DB.GetCF(db.Opts, handle, rawKey)
defer slice.Free()
if err != nil { if err != nil {
return nil, err return nil, err
} else if slice.Size() == 0 { } else if slice.Size() == 0 {
@ -64,6 +65,7 @@ func (db *ReadOnlyDBColumnFamily) GetHeader(height uint32) ([]byte, error) {
key := prefixes.NewHeaderKey(height) key := prefixes.NewHeaderKey(height)
rawKey := key.PackKey() rawKey := key.PackKey()
slice, err := db.DB.GetCF(db.Opts, handle, rawKey) slice, err := db.DB.GetCF(db.Opts, handle, rawKey)
defer slice.Free()
if err != nil { if err != nil {
return nil, err return nil, err
} else if slice.Size() == 0 { } else if slice.Size() == 0 {
@ -127,6 +129,7 @@ func (db *ReadOnlyDBColumnFamily) GetClaimsInChannelCount(channelHash []byte) (u
rawKey := key.PackKey() rawKey := key.PackKey()
slice, err := db.DB.GetCF(db.Opts, handle, rawKey) slice, err := db.DB.GetCF(db.Opts, handle, rawKey)
defer slice.Free()
if err != nil { if err != nil {
return 0, err return 0, err
} else if slice.Size() == 0 { } else if slice.Size() == 0 {
@ -188,6 +191,7 @@ func (db *ReadOnlyDBColumnFamily) GetRepost(claimHash []byte) ([]byte, error) {
key := prefixes.NewRepostKey(claimHash) key := prefixes.NewRepostKey(claimHash)
rawKey := key.PackKey() rawKey := key.PackKey()
slice, err := db.DB.GetCF(db.Opts, handle, rawKey) slice, err := db.DB.GetCF(db.Opts, handle, rawKey)
defer slice.Free()
if err != nil { if err != nil {
return nil, err return nil, err
} else if slice.Size() == 0 { } else if slice.Size() == 0 {
@ -234,6 +238,7 @@ func (db *ReadOnlyDBColumnFamily) GetChannelForClaim(claimHash []byte, txNum uin
key := prefixes.NewClaimToChannelKey(claimHash, txNum, position) key := prefixes.NewClaimToChannelKey(claimHash, txNum, position)
rawKey := key.PackKey() rawKey := key.PackKey()
slice, err := db.DB.GetCF(db.Opts, handle, rawKey) slice, err := db.DB.GetCF(db.Opts, handle, rawKey)
defer slice.Free()
if err != nil { if err != nil {
return nil, err return nil, err
} else if slice.Size() == 0 { } else if slice.Size() == 0 {
@ -300,6 +305,7 @@ func (db *ReadOnlyDBColumnFamily) GetSupportAmount(claimHash []byte) (uint64, er
key := prefixes.NewSupportAmountKey(claimHash) key := prefixes.NewSupportAmountKey(claimHash)
rawKey := key.PackKey() rawKey := key.PackKey()
slice, err := db.DB.GetCF(db.Opts, handle, rawKey) slice, err := db.DB.GetCF(db.Opts, handle, rawKey)
defer slice.Free()
if err != nil { if err != nil {
return 0, err return 0, err
} else if slice.Size() == 0 { } else if slice.Size() == 0 {
@ -322,6 +328,7 @@ func (db *ReadOnlyDBColumnFamily) GetTxHash(txNum uint32) ([]byte, error) {
key := prefixes.NewTxHashKey(txNum) key := prefixes.NewTxHashKey(txNum)
rawKey := key.PackKey() rawKey := key.PackKey()
slice, err := db.DB.GetCF(db.Opts, handle, rawKey) slice, err := db.DB.GetCF(db.Opts, handle, rawKey)
defer slice.Free()
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -355,6 +362,7 @@ func (db *ReadOnlyDBColumnFamily) GetActivationFull(txNum uint32, postition uint
key := prefixes.NewActivationKey(typ, txNum, postition) key := prefixes.NewActivationKey(typ, txNum, postition)
rawKey := key.PackKey() rawKey := key.PackKey()
slice, err := db.DB.GetCF(db.Opts, handle, rawKey) slice, err := db.DB.GetCF(db.Opts, handle, rawKey)
defer slice.Free()
if err != nil { if err != nil {
return 0, err return 0, err
} }
@ -379,6 +387,7 @@ func (db *ReadOnlyDBColumnFamily) GetCachedClaimTxo(claim []byte, useCache bool)
key := prefixes.NewClaimToTXOKey(claim) key := prefixes.NewClaimToTXOKey(claim)
rawKey := key.PackKey() rawKey := key.PackKey()
slice, err := db.DB.GetCF(db.Opts, handle, rawKey) slice, err := db.DB.GetCF(db.Opts, handle, rawKey)
defer slice.Free()
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -418,6 +427,7 @@ func (db *ReadOnlyDBColumnFamily) GetControllingClaim(name string) (*prefixes.Cl
rawKey := key.PackKey() rawKey := key.PackKey()
log.Println(hex.EncodeToString(rawKey)) log.Println(hex.EncodeToString(rawKey))
slice, err := db.DB.GetCF(db.Opts, handle, rawKey) slice, err := db.DB.GetCF(db.Opts, handle, rawKey)
defer slice.Free()
log.Printf("slice: %#v", slice) log.Printf("slice: %#v", slice)
log.Printf("err: %#v", err) log.Printf("err: %#v", err)
@ -468,6 +478,7 @@ func (db *ReadOnlyDBColumnFamily) GetTxCount(height uint32) (*prefixes.TxCountVa
key := prefixes.NewTxCountKey(height) key := prefixes.NewTxCountKey(height)
rawKey := key.PackKey() rawKey := key.PackKey()
slice, err := db.DB.GetCF(db.Opts, handle, rawKey) slice, err := db.DB.GetCF(db.Opts, handle, rawKey)
defer slice.Free()
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -490,6 +501,7 @@ func (db *ReadOnlyDBColumnFamily) GetDBState() (*prefixes.DBStateValue, error) {
key := prefixes.NewDBStateKey() key := prefixes.NewDBStateKey()
rawKey := key.PackKey() rawKey := key.PackKey()
slice, err := db.DB.GetCF(db.Opts, handle, rawKey) slice, err := db.DB.GetCF(db.Opts, handle, rawKey)
defer slice.Free()
if err != nil { if err != nil {
return nil, err return nil, err
} else if slice.Size() == 0 { } else if slice.Size() == 0 {
@ -546,6 +558,7 @@ func (db *ReadOnlyDBColumnFamily) GetCachedClaimHash(txNum uint32, position uint
rawKey := key.PackKey() rawKey := key.PackKey()
slice, err := db.DB.GetCF(db.Opts, handle, rawKey) slice, err := db.DB.GetCF(db.Opts, handle, rawKey)
defer slice.Free()
if err != nil { if err != nil {
return nil, err return nil, err
} else if slice.Size() == 0 { } else if slice.Size() == 0 {

View file

@ -108,9 +108,12 @@ func (opts *IterOptions) ReadRow(prevKey *[]byte) *prefixes.PrefixRowKV {
} }
key := it.Key() key := it.Key()
defer key.Free()
keyData := key.Data() keyData := key.Data()
keyLen := len(keyData) keyLen := len(keyData)
value := it.Value() value := it.Value()
defer value.Free()
valueData := value.Data() valueData := value.Data()
valueLen := len(valueData) valueLen := len(valueData)
@ -156,9 +159,6 @@ func (opts *IterOptions) ReadRow(prevKey *[]byte) *prefixes.PrefixRowKV {
} }
} }
key.Free()
value.Free()
kv := &prefixes.PrefixRowKV{ kv := &prefixes.PrefixRowKV{
Key: outKey, Key: outKey,
Value: outValue, Value: outValue,

View file

@ -5,6 +5,8 @@ import (
"fmt" "fmt"
"time" "time"
_ "net/http/pprof"
pb "github.com/lbryio/hub/protobuf/go" pb "github.com/lbryio/hub/protobuf/go"
"github.com/lbryio/hub/server" "github.com/lbryio/hub/server"
"github.com/lbryio/lbry.go/v2/extras/util" "github.com/lbryio/lbry.go/v2/extras/util"

View file

@ -150,7 +150,7 @@ func (s *Server) Run() {
// initializes everything. It loads information about previously known peers, // initializes everything. It loads information about previously known peers,
// creates needed internal data structures, and initializes goroutines. // creates needed internal data structures, and initializes goroutines.
func MakeHubServer(ctx context.Context, args *Args) *Server { func MakeHubServer(ctx context.Context, args *Args) *Server {
grpcServer := grpc.NewServer(grpc.NumStreamWorkers(10)) grpcServer := grpc.NewServer(grpc.NumStreamWorkers(0))
multiSpaceRe, err := regexp.Compile(`\s{2,}`) multiSpaceRe, err := regexp.Compile(`\s{2,}`)
if err != nil { if err != nil {